I have a Firebase storage which contains photos. I'm organizing the photos by name 1,2,3 and so on.... I'm trying to get all the photos dowload URLs , so in the future i will enter them into Arraylist of URLS and present them in a photo gallery using Glide ( that's why i'm only looking for the URLS )
I'm looking for a method that will keep giving me the Urls only if the onSucsess is called, when onFailure is called (becuase there are no more photos) i want the loop to end.
I'm was trying using the Firebase's getDownloadUrl method and added a boolean which will trigger false when onFailure is called. And increment my photoOrder int which starts at 1,and by that will change the path of the selected photo.
public class Photopackges extends AppCompatActivity {
public static boolean shouldRun = true;
public static final String TAG = "debug";
public static int photoOrder = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_photopackges);
//just normal firebase setup
FirebaseStorage storage = FirebaseStorage.getInstance();
// while shouldRun boolean is true keep going , until it will be defined false
while (shouldRun == true) {
// define my Firebase storage path,which contain one folder called "test" and three photos 1.jpg,2.jpg,3.jpg
// the number of the photo is represented in the photoOrder int.
String storagePath = "test/" + String.valueOf(photoOrder) + ".jpg";
StorageReference ref = storage.getReference().child(storagePath);
try {
ref.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
// trying to define that if the action was successful , keep on going.
shouldRun = true;
Log.e(TAG, "sucsess! " + uri);
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
// trying to define that if the action has failed , stop.
shouldRun = false;
Log.e(TAG, "Fail! " + e);
}
});
} catch (Exception e) {
Log.e(TAG, "Error! " + e);
break;
}
//increment the photoOrder so it will go to the next path.
photoOrder++;
Log.e(TAG,"value of photoOrder "+photoOrder);
}
}
}
the log -
I don't have a problem that he sends more requests before he got the answers. I just need him to stop when it gets
StorageException: Object does not exist at location.
I was guessing that there must be a simpler way to get all the storage using firebase..
Thanks for the help !