0

I'm not able to read data part from the selected image Uri, this happens on some specific device Lg nexus 5 api 6.0.1

Uri of a selected image

content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/200/ORIGINAL/NONE/2077196451

Code used to get data from the uri

 public static String getDataColumn(Context context, Uri uri, String selection,
                                       String[] selectionArgs) {

        Cursor cursor = null;
        final String column = "_data";
        final String[] projection = {
                column
        };

        try {
            cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs,
                    null);
            if (cursor != null && cursor.moveToFirst()) {
                final int index = cursor.getColumnIndexOrThrow(column);
                return cursor.getString(index);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        finally {
            if (cursor != null)
                cursor.close();
        }
        return null;
    }

Not issue with the permissions handling, Required Permissions are given.

ibnekhan
  • 71
  • 1
  • 2
  • your `Uri` is broken: `content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/200/ORIGINAL/NONE/2077196451` - it should be either `content://com.google.android.apps.photos.contentprovider/-1/1/` or `content://media/external/images/media/200/ORIGINAL/NONE/2077196451` – pskink Apr 08 '19 at 16:02
  • Getting this exception `Permission Denial: reading com.google.android.apps.photos.contentprovider.impl.MediaContentProvider uri content://com.google.android.apps.photos.contentprovider/-1/1/ from pid=26928, uid=10168 requires the provider be exported, or grantUriPermission()` – ibnekhan Apr 08 '19 at 16:19
  • using this one `content://media/external/images/media/200/ORIGINAL/NONE/2077196451` – ibnekhan Apr 08 '19 at 16:41
  • @pskink `Intent getIntent = new Intent(Intent.ACTION_GET_CONTENT); getIntent.setType("application/pdf"); Intent pickIntent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI).setType("image/*"); Intent chooserIntent = Intent.createChooser(getIntent, "Select File"); chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, new Intent[] {pickIntent}); activity.startActivityForResult(chooserIntent, REQUEST_PICK_FILE);` – ibnekhan Apr 08 '19 at 16:55

0 Answers0