【问题标题】:How to avoid downloading image from firebase if i have already downloaded previously?如果我之前已经下载过,如何避免从 firebase 下载图像?
【发布时间】:2019-10-27 17:47:46
【问题描述】:

我正在尝试从 firebase 数据库存储图像并将其命名为 FirebaseuniqUserID.jpeg。(如 buwkgefuikbuifbkc8gfybfy.jpeg)。用户可以随时更改图像。 为了从 firebase 实时数据库中获取图片链接,我使用了 addListenerForSingleValueEvent。

FirebaseDatabase.getInstance().getReference().child("Users").child(FirebaseuniqUserID).addListenerForSingleValueEvent(new ValueEventListener() {
    @Override
    public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
        //here i am downloading image//
        //and named it FirebaseuniqUserID.jpeg
    }

现在的问题是,每次下载图像时都会调用此侦听器。 但现在我想避免下载,如果当前用户在 firebase 中有最新更新的用户图像,以减少 firebase 下载的数据。

【问题讨论】:

  • 你的逻辑是什么来决定图像是否在 firebase 中更新?
  • 是的,兄弟,你知道我需要如何准备这个逻辑以避免在 firebase 中下载。?
  • “用户”节点就像google.com/…

标签: android firebase firebase-realtime-database


【解决方案1】:

如果当前用户在 Firebase 中有用户的最新更新图像,我想避免下载

要解决这个问题,我绝对建议您使用图像加载和缓存库。对于 Android,我们有 Glide:

Glide 是一个快速高效的 Android 开源媒体管理和图像加载框架,它将媒体解码、内存和磁盘缓存以及资源池封装到一个简单易用的界面中。

【讨论】:

    【解决方案2】:

    您可以使用两个不同的选项,第一个是Glide,第二个是,您可以将图像下载状态保存在本地数据库文件或 SharePreferences 中。但是图像缓存是最好的解决方案。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-02-01
      • 2013-07-07
      • 2019-11-25
      • 2020-01-09
      • 1970-01-01
      相关资源
      最近更新 更多