Home > OS >  How to set ImageView with URI correctly?
How to set ImageView with URI correctly?

Time:11-15

I am using local database ROOM to store some uri from phone but I can't reload it in the second times.

The exception is:

E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.andiogame, PID: 2878
java.lang.SecurityException: com.example.andiogame has no access to content://media/external/images/media/24
    at android.os.Parcel.createExceptionOrNull(Parcel.java:2385)

The code is:

Uri uri = Uri.parse(simpleMessage.getUri());
imageView.setImageURI(uri);

CodePudding user response:

Try this

Uri uri = Uri.parse(simpleMessage.getUri());
imageView.setImageURI(null); 
imageView.setImageURI(uri);

CodePudding user response:

Did you declare permission to read external storage.

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

Also, if you're targeting Android 23 (which you probably are), you need to ask for permissions at runtime.

  • Related