The path //media/external/images/media/16
is a Media Uri
...You have to get the actual file path from the Uri
and then set the image to the ImageView
.
Get the real file path from Media Uri
as below and the returned path is absolute file path...
public String getRealPathFromURI(Context context, Uri contentUri) {
Cursor cursor = null;
try {
String[] proj = { MediaStore.Images.Media.DATA };
cursor = context.getContentResolver().query(contentUri, proj, null, null, null);
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
} finally {
if (cursor != null) {
cursor.close();
}
}
}
Get Bitmap
from the path returned by getRealPathFromURI()
method as below...
Context mContext;
public loadImageTask(Context context, ImageView imv) {
this.mContext = context;
this.imv = imv;
this.path = agenda.caminho_imagem;
}
@Override
protected Bitmap doInBackground(Agenda... params) {
Log.w("Livro", "path: "+path);
File file = new File(getRealPathFromURI(mContext, path));
if(file.exists()){
b = BitmapFactory.decodeFile(file.getAbsolutePath());
}
return b;
}
And pass the context of the activity through the asynctask constructor as below...
new loadImageTask(context, viewHolder.mImagem).execute();