Glide签名方法我做错了什么?

时间:2017-05-09 03:03:41

标签: android firebase firebase-storage android-glide

这就是我所拥有的:

Button button2 = (Button) findViewById(R.id.button2);
button2.setOnClickListener(new View.OnClickListener() {
    @Override
    public void onClick(View v) {
        try {
            String str = "images.jpg";

            for (int i = 0; i < images.size(); i++) {
                str = str.substring(0, 6) + i + ".jpg";
                StorageReference storageReference = FirebaseStorage.getInstance().getReference().child(str);
                File localFile = File.createTempFile("images" + i, "jpg");
                Glide.with(MainActivity.this).load(storageReference).signature(new StringSignature(localFile.length() + "@" + localFile.lastModified())).into(images.get(i));
            }
        }
        catch (IOException e)
        {

        }

    }
});

单击按钮后,我的应用程序崩溃了。

我基本上想要刷新ImageView,这样当我在Firebase存储中更改图像时,单击按钮时图像会更新。

1 个答案:

答案 0 :(得分:0)

从Firebase StorageReference加载需要使用FirebaseImageLoader()

Glide.with(MainActivity.this)
    .using(new FirebaseImageLoader()) // <== ADD THIS
    .load(storageReference)
    .signature(new StringSignature(localFile.length() + "@" + localFile.lastModified()))
    .into(images.get(i));

您将需要此构建依赖项:

dependencies {
    ...
    compile 'com.firebaseui:firebase-ui-storage:1.2.0'
}