Requires android.permission.READ_EXTERNAL_STORAGE or grantUriPermission () error?

I think that since the last Android update this method:

public String getPath(Uri uri) {
    Cursor cursor = getContentResolver().query(uri, null, null, null, null);
    cursor.moveToFirst();
    String document_id = cursor.getString(0);
    document_id = document_id.substring(document_id.lastIndexOf(":") + 1);
    cursor.close();

    cursor = getContentResolver().query(
            android.provider.MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
            null, MediaStore.Images.Media._ID + " = ? ", new String[]{document_id}, null);
    cursor.moveToFirst();
    String path = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA));
    cursor.close();

    return path;
}

doesn't work because i need some kind of permission. is there a fix

0
source share
1 answer

You need to save permissions READ_EXTERNAL_STORAGEor WRITE_EXTERNAL_STORAGE. It includes:

  • putting the appropriate element <uses-permission>in your manifest and

  • if your targetSdkVersionis 23 or higher, request permission at runtime from the user, as these permissionsdangerous

+2
source

All Articles