user7702
user7702

Reputation: 355

Android Picasso not loading image from local file system

I'm using Picasso 2.7 to load images from web and the local file system. I'm facing an issue where Picasso is not loading the image from the local file system at all. Here is the code snippet:

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);
                                }
                            });

What happens is the imageView stays empty and is never populated with the error image. None of the callback methods in Callback are ever called, so the request doesn't seem to ever complete or error out.

I looked at the Picasso logs generated and see that the Picasso request to retrieve the image file is kicked off:

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

However unlike the other Picasso tasks I also have running, I never see the above Picasso request completed (seems like just stuck in executing), which might explain why onSuccess and onError are never called.

I double checked the file path exists and if I pull the file in myself, convert it to a bitmap and load it into the imageView manually (not through picasso), the imageView is populated correctly. Also, I'm able to pull images from valid URLs so that part is working, it just doesn't seem to be working with images on the local file system (and yes i do have WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions).

I've also tried using File instead of just the local file path, same issue. At this point I'm not sure what can be wrong and any insight or advice would be greatly appreciated.

Upvotes: 1

Views: 783

Answers (1)

Darshan Komu
Darshan Komu

Reputation: 186

Try this out String filePath = "file://sdcard/ic_download_normal.png";

Upvotes: 0

Related Questions