I want to download an image file uploaded on Firebase Storage from background service of my application. I need service because the database is too large and storage also. That is why, I want to download all the data from Firebase in background to keep my UI consistent. All the data from Firebase Database downloaded successfully.But downloading file from Firebase storage gives me error.
CODE :
StorageReference httpsReference = FirebaseStorage.getInstance().getReferenceFromUrl(url);
httpsReference.getBytes(1024 * 1024).addOnSuccessListener(new OnSuccessListener<byte[]>() {
@Override
public void onSuccess(byte[] bytes) {
Log.v("log_tag", "onDataChange onSuccess icon received");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception e) {
}
});
ERROR :
java.lang.IllegalStateException: FirebaseApp with name [DEFAULT] doesn't exist.
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.FirebaseApp.getInstance(Unknown Source)
at com.google.firebase.storage.FirebaseStorage.getInstance(Unknown Source) at in.co.cybercom.memorymatch.misc.WebServiceCommon.downloadImageSet(WebServiceCommon.java:133)
atin.co.cybercom.memorymatch.misc.WebServiceCommon.access$400(WebServiceCommon.java:49)
atin.co.cybercom.memorymatch.misc.WebServiceCommon$1.onDataChange(WebServiceCommon.java:91)
at com.firebase.client.Query$1.onDataChange(Query.java:158)
atcom.firebase.client.core.ValueEventRegistration.fireEvent(ValueEventRegistration.java:45)
at com.firebase.client.core.view.DataEvent.fire(DataEvent.java:45)
at com.firebase.client.core.view.EventRaiser$1.run(EventRaiser.java:38)
at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at android.os.Looper.loop(Looper.java:145) at android.app.ActivityThread.main(ActivityThread.java:5951) at java.lang.reflect.Method.invoke(Native Method) at java.lang.reflect.Method.invoke(Method.java:372) atcom.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1400) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1195)
Please let me know is it possible to download Firebase storage file in background service? If yes then how? and if not then is there any alternative for this scenario? Any help would be appreciated. Thanks.