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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With