Reputation: 706
I think ever since the newest 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;
}
wont work because i need some kind of permission. is there a fix?
Upvotes: 0
Views: 3121
Reputation: 1006819
You need to hold the READ_EXTERNAL_STORAGE
or WRITE_EXTERNAL_STORAGE
permission. That involves:
putting the appropriate <uses-permission>
element in your manifest, and
if your targetSdkVersion
is 23 or higher, requesting the permission at runtime from the user, as those permissions are dangerous
Upvotes: 4