【问题标题】:Retrieving and setting an image from firebase storage?从 Firebase 存储中检索和设置图像?
【发布时间】:2020-10-04 00:19:37
【问题描述】:

几个小时以来,我一直在尝试从 Firebase 存储中检索和设置图像,但我似乎无法获得它。

我已经尝试使用 Bitmap 和 setImageBitmap(),但是当我加载 Activity 时我的应用程序崩溃了。

我也尝试过使用 Glide。还会使我的活动崩溃。我尝试使用不同的图像,认为这可能是原因,但仍然崩溃。

我当前的代码是:

mStorageReference = FirebaseStorage.getInstance().getReference().child(photoUrl);

mStorageReference.getDownloadUrl();

Glide.with(this).load(mStorageReference).into(phProfilePhoto);

使用依赖项:

implementation 'com.github.bumptech.glide:glide:4.11.0'

annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'

implementation 'com.firebaseui:firebase-ui-storage:6.3.0'

【问题讨论】:

    标签: java android firebase firebase-storage


    【解决方案1】:

    由于您包含 FirebaseUI (firebase-ui-storage),因此您无需调用 getDownloadUrl,可以直接将 StorageReference 传递给 Glide。

    mStorageReference = FirebaseStorage.getInstance().getReference().child(photoUrl);
    
    Glide.with(this).load(mStorageReference).into(phProfilePhoto);
    

    如果这使您的应用崩溃,请编辑您的问题以包含确切的错误消息和您在其 logcat 输出中获得的完整堆栈跟踪。

    【讨论】:

    • 我添加了监听器,但它仍然让我的应用程序崩溃。它成功了,但在 Glide.with(this).load(mStorageReference).into(imageView); 线上崩溃了;
    • 对使用logcat有帮助,谢谢!直到现在从未真正使用过。 phProfilePhoto 指向不同活动 smh 中的图像视图。
    猜你喜欢
    • 2020-10-23
    • 1970-01-01
    • 2017-08-30
    • 2017-02-23
    • 1970-01-01
    • 2017-09-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多