I was thinking about making View-pager in android. Which retrieves slider images from a server, so that I can change those slider images at any time. I know for this I have to pass an image URL in JSON format. But I am not understanding how to get those image urls so that I can pass those image URLs in JSON format.
I tried to store an image in Storage of the Firebase. I don't know if this is the right way or not? I uploaded this image on firebase storage below this image there is a storage location url can i use that storage location url in json?
Yes,You have stored it right.You can use following code to get download url:
Just replace path with your image path eg images/6401.jpg
final StorageReference ref = storageRef.child("path");
uploadTask = ref.putFile(file);
Task<Uri> urlTask = uploadTask.continueWithTask(new Continuation<UploadTask.TaskSnapshot, Task<Uri>>() {
@Override
public Task<Uri> then(@NonNull Task<UploadTask.TaskSnapshot> task) throws Exception {
if (!task.isSuccessful()) {
throw task.getException();
}
// Continue with the task to get the download URL
return ref.getDownloadUrl();
}
}).addOnCompleteListener(new OnCompleteListener<Uri>() {
@Override
public void onComplete(@NonNull Task<Uri> task) {
if (task.isSuccessful()) {
//Your image url do something with it.
Uri downloadUri = task.getResult();
} else {
// Handle failures
// ...
}
}
});
Fore more info on this please visit this site here: https://firebase.google.com/docs/storage/android/upload-files
Or
To see complete example you can use this link: https://github.com/firebase/snippets-android/blob/1c8f86671919fccd43178488fc4799d49f27d786/storage/app/src/main/java/com/google/firebase/referencecode/storage/StorageActivity.java#L309-L332
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.