0

I am trying to use Firestore. I need to get all images urls which are stored in a folder in Firestore. I am currently following This.

When using:

db.collection("images")
    .get()
    .addOnCompleteListener(new OnCompleteListener<QuerySnapshot>() {
        @Override
        public void onComplete(@NonNull Task<QuerySnapshot> task) {
            if (task.isSuccessful()) {
                for (QueryDocumentSnapshot document : task.getResult()) {
                    Log.d(TAG, document.getId() + " => " + document.getData());
                }
            } else {
                Log.w(TAG, "Error getting documents.", task.getException());
            }
        }
    });

I am getting the error below.

Initially i was getting

Program type already present: com.google.common.annotations.GwtCompatible

That was resolved by :

implementation ("com.google.firebase:firebase-firestore:17.0.3"){
    exclude group: 'com.google.guava'
}

java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
    at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
    at com.google.firebase.firestore.g.zzd.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 Caused by: java.lang.NoSuchMethodError: No static method checkArgument(ZLjava/lang/String;I)V in class Lcom/google/common/base/Preconditions; or its super classes (declaration of 'com.google.common.base.Preconditions' appears in /data/app/com.apps.dp-2wjpiDlhe60_b_F7OtfpaQ==/split_lib_dependencies_apk.apk!classes2.dex)
    at com.google.firebase.Timestamp.zza(SourceFile:136)
    at com.google.firebase.Timestamp.<init>(SourceFile:47)
    at com.google.firebase.firestore.d.zzm.<clinit>(SourceFile:12)
    at com.google.firebase.firestore.c.zzav.<init>(SourceFile:24)
    at com.google.firebase.firestore.c.zzat.zzb(SourceFile:104)
    at com.google.firebase.firestore.c.zzi.<init>(SourceFile:125)
    at com.google.firebase.firestore.b.zzf.zza(SourceFile:1215)
    at com.google.firebase.firestore.b.zzh.run(Unknown Source:8)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at com.google.firebase.firestore.g.zza$zza.run(SourceFile:190)
    at java.lang.Thread.run(Thread.java:764)
    07-26 09:56:29.396 25793-25793/com.apps.dp E/UncaughtException: 
    java.lang.RuntimeException: Internal error in Firestore (0.6.6-dev).
    at com.google.firebase.firestore.g.zza.zzb(SourceFile:324)
    at com.google.firebase.firestore.g.zzd.run(Unknown Source:2)
    at android.os.Handler.handleCallback(Handler.java:790)
    at android.os.Handler.dispatchMessage(Handler.java:99)
    at android.os.Looper.loop(Looper.java:164)
    at android.app.ActivityThread.main(ActivityThread.java:6494)
    at java.lang.reflect.Method.invoke(Native Method)
    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:438)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807)
 Caused by: java.lang.NoSuchMethodError: No static method checkArgument(ZLjava/lang/String;I)V in class Lcom/google/common/base/Preconditions; or its super classes (declaration of 'com.google.common.base.Preconditions' appears in /data/app/com.apps.dp-2wjpiDlhe60_b_F7OtfpaQ==/split_lib_dependencies_apk.apk!classes2.dex)
    at com.google.firebase.Timestamp.zza(SourceFile:136)
    at com.google.firebase.Timestamp.<init>(SourceFile:47)
    at com.google.firebase.firestore.d.zzm.<clinit>(SourceFile:12)
    at com.google.firebase.firestore.c.zzav.<init>(SourceFile:24)
    at com.google.firebase.firestore.c.zzat.zzb(SourceFile:104)
    at com.google.firebase.firestore.c.zzi.<init>(SourceFile:125)
    at com.google.firebase.firestore.b.zzf.zza(SourceFile:1215)
    at com.google.firebase.firestore.b.zzh.run(Unknown Source:8)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:457)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:301)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1162)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:636)
    at com.google.firebase.firestore.g.zza$zza.run(SourceFile:190)
    at java.lang.Thread.run(Thread.java:764)

I am struggling on this from last 6 hours . Can i get some help on this . I have a question also is it possible to get all images urls from a folder using Firestore APi in android . Or i have save those URls in Firebase database first ? Already checked out some posts on this Like this one which says its not possible .

Community
  • 1
  • 1
Diaz diaz
  • 284
  • 1
  • 7
  • 21
  • You have to first store the url of all the images in the firestore database using collection and document concept. Then you can retrieve that url's. – Raj Jul 26 '18 at 05:16
  • You mean i have to first store all urls in real time database ? Is this the ultimate solution in year 2018 . Cause thats what this 2016 post says which i have posted in question . – Diaz diaz Jul 26 '18 at 05:24
  • For latest answer you can refer https://stackoverflow.com/questions/49726579/get-list-of-images-from-firebase-store. – Raj Jul 26 '18 at 05:49
  • Yeah Thats what i said `FirebaseDatabase` is involved in the solution . – Diaz diaz Jul 26 '18 at 06:00
  • @Diazdiaz Have you tried my answer from this [post](https://stackoverflow.com/questions/51460300/firestore-crash-runtimeexception-trying-to-get-collection) to solve that error? – Alex Mamo Jul 26 '18 at 08:51
  • Thihs is for proguard . I am not using it in debug mode . I am stuck here for almost 8 hours now . – Diaz diaz Jul 26 '18 at 10:33
  • @AlexMamo can you give me some advise on that . How can i get all images urls from Firestore ? Just read the last paragraph in my question . – Diaz diaz Jul 28 '18 at 04:31

1 Answers1

3

According to your last comment, please note that in order to retrieve all the documents within a folder which is hosted in Cloud Storage for Firebase, you need to know either the path or the download URL. There's no way to simply get all your files from a folder without knowing it.

To solve this, I recommend that upon uploading any file, store the download URL to a database like Firebase Real-time Database or the new Cloud Firestore. Please see below a simple example of getting the download URL.

storageRef.child("YourFolderName").getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
    @Override
    public void onSuccess(Uri uri) {
        // Got the download URL for "YourFolderName/YourFile.pdf"
        // Add it to your database
    }
}).addOnFailureListener(new OnFailureListener() {
    @Override
    public void onFailure(@NonNull Exception exception) {
        // Handle any errors
    }
});

In the end just query the url node from the Firebase Real-time Database or the url collection from Cloud Firestore and use them wherever needed.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193