In My Application I am trying to Pick image from galley, so as to pass that image to server.
Code is working fine on Android 5 and below, but for Android 6 on Nexus 5 I am not able to get image information. Log trace which I got
Note: Code is working fine on Android 5 and below versions
11-06 12:27:43.736: W/System.err(31678): java.lang.SecurityException: Permission Denial: reading com.google.android.apps.photos.contentprovider.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/0/1/content%3A//media/external/images/media/19138/ACTUAL/94710853 from pid=31678, uid=10111 requires the provider be exported, or grantUriPermission()
11-06 12:27:43.757: W/System.err(31678):
at android.os.Parcel.readException(Parcel.java:1599)
11-06 12:27:43.757: W/System.err(31678):
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:183)
11-06 12:27:43.757: W/System.err(31678):
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:135)
11-06 12:27:43.757: W/System.err(31678):
at android.content.ContentProviderProxy.query(ContentProviderNative.java:421)
11-06 12:27:43.757: W/System.err(31678):
at android.content.ContentResolver.query(ContentResolver.java:491)
11-06 12:27:43.757: W/System.err(31678):
at android.content.ContentResolver.query(ContentResolver.java:434)
11-06 12:27:43.758: W/System.err(31678):
at org.apache.cordova.file.ContentFilesystem.openCursorForURL(ContentFilesystem.java:258)
11-06 12:27:43.758: W/System.err(31678):
at org.apache.cordova.file.ContentFilesystem.getFileMetadataForLocalURL(ContentFilesystem.java:169)
11-06 12:27:43.758: W/System.err(31678):
at org.apache.cordova.file.FileUtils.getFileMetadata(FileUtils.java:822)
11-06 12:27:43.758: W/System.err(31678):
at org.apache.cordova.file.FileUtils.access$500(FileUtils.java:52)
11-06 12:27:43.758: W/System.err(31678):
at org.apache.cordova.file.FileUtils$15.run(FileUtils.java:394)
11-06 12:27:43.758: W/System.err(31678):
at org.apache.cordova.file.FileUtils$25.run(FileUtils.java:551)
11-06 12:27:43.758: W/System.err(31678):
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1113)
11-06 12:27:43.758: W/System.err(31678):
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
11-06 12:27:43.758: W/System.err(31678):
at java.lang.Thread.run(Thread.java:818)
DO it this way... on Button Click check for SDK Version
after that in Override method onRequestPermissionsResult write this code:
After that
Try this
This is the simple method that i have created with other examples
call CHECKGALLERYPERMISSION() method where you want and paste the code inside method
Note
I had the same issue. The image showed in Imageview after picking the image from gallery using
and decoding the bitmap image from the URI
But saving the URI for future use and reopening the app and reusing the saved URI not worked. Couldn't decoding the bitmap from URI.
I solved the issue by extracting the original content uri from URI path
I believe you'll need to request the permissions to the user at runtime (this is one of the most noticeable changes from api 22 to 23).
You can try this snippet, extracted from the Android Developers permission page
Let me know if it helped.
In order to get image from Gallery in Marshmallow, You are required to grant READ_EXTERNAL_STORAGE permission at run time. Android Version M has changed the way permissions are granted to applications.
Before Marshmallow, all required permissions are granted at once and that is at the time of installation. But in Marshmallow, User is asked for permission at the time only if that permission is required, and the User has to either Allow or Deny that permission.
Below two links will help you more. Link 1 is from official documentation of Android, and Link 2 is a blog which has explained this issue with a working example.
Link1: http://developer.android.com/training/permissions/requesting.html
Link2: http://inthecheesefactory.com/blog/things-you-need-to-know-about-android-m-permission-developer-edition/en