Picasso library does not load images from SD card on Android

I take a file from path from image gallery and try to load it a image view as follows. File path is: /storage/sdcard0/DCIM/Camera/1436267579864.jpg. I also tried passing Uri I also have read privileges to SD card.

It ends up in onError() method. However similar method works fine for web urls. How can I resolve this?

private void getImage(File file) {

        if(file.exists()) {

            Picasso.with(activity)
                    .load(file)
                    .error(R.drawable.noimage)
                    .into(imgPreview, new Callback() {
                        @Override
                        public void onSuccess() {
                            if (progressBar != null && imgPreview != null) {

                                imgPreview.setVisibility(View.VISIBLE);
                                imgPreview.setTag("loaded");
                                progressBar.setVisibility(View.GONE);

                            }
                        }

                        @Override
                        public void onError() {
                            if (progressBar != null && imgPreview != null) {
                                imgPreview.setVisibility(View.VISIBLE);
                                progressBar.setVisibility(View.GONE);
                            }
                        }

                    });
   }


<uses-sdk
    android:minSdkVersion="11"
    android:targetSdkVersion="21" />

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

Though it is too late , but I stuck into same problem, so I solved in the following way . Just using and appending "file://" in the starting of path. take a look at this:

 Picasso.with(context) //
                    .load("file://" +myFilePath) //
                    .error(R.mipmap.error)
                    .placeholder(R.mipmap.ic_launcher)
                    .fit()
                    .tag(MyActivity.this) //
                    .into(imageView, new ImageLoadedCallback(progressBar) {
                        @Override
                        public void onSuccess() {
                            progressBar.setVisibility(View.GONE);
                        }

                        @Override
                        public void onError() {
                            Log.d("Picasso Error", "Error");

                        }
                    });

This solves my problem . Just answering so that if some one fall in the same problem and came here for solution then he may get his problem solved through this.

链接地址: http://www.djcxy.com/p/27286.html

上一篇: 为什么md工具提示未应用于md虚拟选项卡

下一篇: 毕加索图书馆不从Android上的SD卡加载图像