I've recently been writing a program on android studio that extract call log and contacts from phone and stores it in firebase realtime database. Does anyone know how to extract latest image from gallery and store it in firebase storage? Thank you in advance
Asked
Active
Viewed 43 times
1 Answers
1
am new at android , i use this to upload image to firebase storage imageUri is the path of the image upload from the gallery and imageUrl is the path of the image in firebase storage
public String getExtension(Uri uri) {
ContentResolver contentResolver = getContentResolver();
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
return mimeTypeMap.getMimeTypeFromExtension(contentResolver.getType(uri));
}
private void uploadImage() {
final StorageReference reference = mStorageReference.child(System.currentTimeMillis() + "." + getExtension(imageUri));
reference.putFile(imageUri).addOnSuccessListener(new OnSuccessListener<UploadTask.TaskSnapshot>() {
@Override
public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) {
taskSnapshot.getStorage().getDownloadUrl()
.addOnSuccessListener(
new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
//to get the path of the image in the firebase storage
String imageUrl = uri.toString();
}
}
);
}
});
}

Abdulkarim
- 547
- 3
- 13
-
and check that it may help u https://stackoverflow.com/a/8557147/14137110 – Abdulkarim Aug 22 '20 at 16:36
-
Thank you, with a bit of tweaking it worked!!! – tareklk Aug 22 '20 at 23:29