Click here to Skip to main content
15,890,123 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am trying retrieve image but it's not working if i restart my application

i am getting this error

E/path: getRealPathFromURI Exception : java.lang.SecurityException: Permission Denial: opening provider com.google.android.apps.photos.contentprovider.impl.MediaContentProvider from ProcessRecord{c3b0cec 9068:com.rayvatapps.launcher/u0a94} (pid=9068, uid=10094) that is not exported from UID 10066

E/BitmapFactory: Unable to decode stream: java.io.FileNotFoundException: / (Permission denied)

please help me any suggestion would be helpful

What I have tried:

<pre>SharedPreferences sharedPreferences = getSharedPreferences("MyFile", 0);

String image = sharedPreferences.getString("image","");

if(!image.equals(""))

{

Uri path = Uri.parse(image);

if(!path.equals(""))

{

File f = new File(getRealPathFromURI(mContext,path));

Drawable d = Drawable.createFromPath(f.getAbsolutePath());

rlMain.setBackground(d);

}

}

method
private 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);

} catch (Exception e) {

Log.e("Path", "getRealPathFromURI Exception : " + e.toString());

return "";

} finally {

if (cursor != null) {

cursor.close();

}

}

}
Posted
Updated 21-Aug-18 21:07pm
v4
Comments
David Crow 23-Aug-18 15:47pm    
Looks like you may need to use a FileProvider. See here and here.
Mitesh Makwana 23-Aug-18 23:49pm    
thank you for the suggestion I'll use it next time.

1 solution

I solve my problem by saving path of the image instead of image Uri in shared preference.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900