I want to download certain images from firebase storage (by adding the downlaodURLs to a list) based on some values taken from firebase firestore. More precisely I want to download an image from firebase storage, if its downloadURL's string value contains the name taken from a document in firestore. The code is given below.
FirebaseFirestore firestore = FirebaseFirestore.getInstance();
CollectionReference ref = firestore.collection("games");
ref.get().addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
@Override
public void onComplete(@NonNull Task<QuerySnapshot> task) {
for(QueryDocumentSnapshot document : task.getResult()){
String formattedName = ((String) document.getData().get("name")).replaceAll(" ", "-").replaceAll(":", "").replaceAll("'","");
imageNames.add(formattedName);
}
download(listRef, imageNames);
}
});
When I call the function download(), I keep taking a message on the console saying :
"W/NetworkRequest: no auth token for request No App Check token for request."
The code for download() is given below.
public void download(StorageReference listRef, ArrayList<String> formattedNames){
listRef.listAll().addOnSuccessListener(new OnSuccessListener<ListResult>() {
@Override
public void onSuccess(ListResult listResult) {
for(StorageReference file:listResult.getItems()){
file.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
if(formattedNames.contains(uri.toString())){
imagelist.add(uri.toString());
Log.e("Itemvalue","" + uri.toString());
}
}
}).addOnSuccessListener(new OnSuccessListener<Uri>() {
@Override
public void onSuccess(Uri uri) {
recyclerView.setAdapter(adapter);
progressBar.setVisibility(View.GONE);
}
});
}
}
});
}
As far as I understood I can't do what I want because onComplete() and onSuccess() work asynchronously, can someone help me? Thanks for your time.