Android Picasso无法从本地文件系统加载图像

问题描述 投票:0回答:1

我正在使用Picasso 2.7从Web和本地文件系统加载图像。我面临一个问题,其中毕加索根本没有从本地文件系统加载图像。这是代码片段:

String filePath = "file:///sdcard/ic_download_normal.png";
Picasso.get().setLoggingEnabled(true);
Picasso.get().load(filePath.trim())
             .error(R.drawable.error)
             .into(imageView, new Callback() {
                                @Override
                                public void onSuccess() {
                                    Log.error(TAG, "Successfully loaded image into view");
                                }

                                @Override
                                public void onError(Exception e) {
                                    Log.error(TAG, "Error loading file: " + e);
                                }
                            });

发生的情况是imageView保持为空,并且永远不会填充错误图像。没有调用过Callback中的任何回调方法,因此请求似乎从未完成或出错。

我看了生成的毕加索日志,发现开始检索图像文件的毕加索请求:

D/Picasso: Main        created      [R1] Request{file:///sdcard/ic_download_normal.png}
D/Picasso: Dispatcher  enqueued     [R1]+27ms
D/Picasso: Hunter      executing    [R1]+28ms

但是与我也正在运行的其他毕加索任务不同,我从未看到上述毕加索请求完成(似乎只是停留在执行中,这可能解释了为什么永不调用onSuccess和onError的原因。)>

我仔细检查了文件路径是否存在,如果我自己提取文件,将其转换为位图,然后手动将其加载到imageView中(而不是通过picasso加载),则会正确填充imageView。另外,我能够从有效的URL中提取图像,以便该部分正常工作,似乎与本地文件系统上的图像不兼容(是的,我确实具有WRITE_EXTERNAL_STORAGE和READ_EXTERNAL_STORAGE权限)。

我也尝试过使用File而不只是本地文件路径,这是同样的问题。在这一点上,我不确定可能出什么问题,对任何见解或建议都将不胜感激。

我正在使用Picasso 2.7从Web和本地文件系统加载图像。我面临一个问题,其中毕加索根本没有从本地文件系统加载图像。这是代码段:...

android imageview picasso
1个回答
0
投票

尝试一下String filePath = "file://sdcard/ic_download_normal.png";

最新问题
© www.soinside.com 2019 - 2024. All rights reserved.