파이어베이스 안드로이드 사진 다운받기 getFile, FileOutputStream, BitmapFactory
파일이 있는지 확인하고 없으면 파일 생성
다운로드한 파일은 비트맵 jpeg 압축 후 저장
/* 파일이 있는지 확인 */
File file = new File(getFilesDir(), "UserProfile");
if(!file.isFile()) {
/* 파이어베이스 서버에서 프로필 이미지를 다운받음 */
try {
/* 임시파일 생성 */
File tempFile = File.createTempFile("images", "jpeg");
StorageReference sgRef = FirebaseStorage.getInstance().getReference();
sgRef.child("UserAccount")
.child("Email")
.child(userAccount.getUid())
.child("ProfileImage").getFile(tempFile).addOnSuccessListener(taskSnapshot -> {
try{
FileOutputStream fos = openFileOutput("UserProfile", Context.MODE_PRIVATE);
Bitmap bitmap = BitmapFactory.decodeFile(tempFile.getPath());
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, fos);
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (IOException e) {
e.printStackTrace();
}
}
'정리 전 게시글 > 공부 관련' 카테고리의 다른 글
| 이것이 자바다 3장 확인문제(연습문제) 답 - 신용권의 Java 프로그래밍 정복 (0) | 2022.09.27 |
|---|---|
| 안드로이드 csv 파일 선택해서 불러오기 (0) | 2022.09.26 |
| 자바, 안드로이드 비밀번호, 닉네임 정규식 (0) | 2022.09.24 |
| 네이버 금융 주식 데이터 웹 크롤링 - 일별시세 csv파일에 저장하기 (4) | 2022.09.21 |
| [JAVA] 파이어베이스 안드로이드 회원가입, 로그인 이메일 인증 완료하기 (0) | 2022.09.21 |