Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Image from Firebase Storage using Glide

I am trying to load an image from Firebase Storage using Glide but I am getting an error .

package com.kanishq.wallpaper;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.firebase.ui.storage.images.FirebaseImageLoader;
import com.google.firebase.storage.FirebaseStorage;
import com.google.firebase.storage.StorageReference;

public class Picture_act extends AppCompatActivity{
ImageView i1;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.picture_activity);
    FirebaseStorage storage = FirebaseStorage.getInstance();
    StorageReference storageReference = storage.getReference();
    i1 = (ImageView) findViewById(R.id.full_picture);
    Glide.with(this).using(new 
FirebaseImageLoader()).load(storageReference).into(i1);
}
}

Gradle File -

dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', {
    exclude group: 'com.android.support', module: 'support-annotations'
})
compile 'com.google.firebase:firebase-storage:11.4.2'
compile 'com.google.firebase:firebase-auth:11.4.2'
compile 'com.firebaseui:firebase-ui-storage:3.0.0'
compile 'com.android.support:appcompat-v7:25.1.0'
compile 'com.android.support:design:25.1.0'
compile 'com.github.devlight.navigationtabstrip:navigationtabstrip:1.0.4'

testCompile 'junit:junit:4.12'
compile 'com.github.bumptech.glide:glide:3.8.0'
annotationProcessor 'com.github.bumptech.glide:compiler:4.2.0'

}
apply plugin: 'com.google.gms.google-services'

I am getting a error:

error

like image 824
Kanishq Gupta Avatar asked Oct 09 '17 17:10

Kanishq Gupta


2 Answers

It seems that with Firebase UI 3.0.0, Firebase has Glide 4.0 support and has changed the way the data is loaded using Glide. According to documentation at Github:

To load an image from a StorageReference, first register in your AppGlideModule:

@GlideModule
public class MyAppGlideModule extends AppGlideModule {
    @Override
    public void registerComponents(Context context, Registry registry) {
        // Register FirebaseImageLoader to handle StorageReference
        registry.append(StorageReference.class, InputStream.class,
                new FirebaseImageLoader.Factory());
    }
}

Then you can load a StorageReference into an ImageView:

// Reference to an image file in Cloud Storage
StorageReference storageReference = ...;

// ImageView in your Activity
ImageView imageView = ...;

// Download directly from StorageReference using Glide
// (See MyAppGlideModule for Loader registration)
GlideApp.with(this /* context */)
    .load(storageReference)
    .into(imageView);

(Source: https://github.com/firebase/FirebaseUI-Android/tree/master/storage)

If you downgrade Firebase UI to 2.4.0, your code should work, however in that case you will most probably receive mixing version errors with support libraries.

like image 174
merterpam Avatar answered Oct 03 '22 13:10

merterpam


Try this way:

storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener<Uri>() {
                    @Override
                    public void onSuccess(Uri uri) {
                        imageURL = uri.toString();
                        Glide.with(getApplicationContext()).load(imageURL).into(i1);
                    }
                }).addOnFailureListener(new OnFailureListener() {
                    @Override
                    public void onFailure(@NonNull Exception exception) {
                        // Handle any errors
                    }
                });

So this way, you get a URL to the image in the storage and you load that URL into the glide

like image 33
Yunus Kulyyev Avatar answered Oct 03 '22 15:10

Yunus Kulyyev