'Grant permission access to 'All downloads' in Android
I'm having trouble trying to access 'all downloads' to get its path. Here is my function to get the full path from a URI. I have tried to add android.permission.ACCESS_ALL_DOWNLOADS in androidManifest but it shows the below error. Does anyone know how to solve this problem? Any help is appreciated.
Code:
if (isDownloadsDocument(uri)) {
final String id = DocumentsContract.getDocumentId(uri);
if (id != null && id.startsWith("raw:")) {
return id.substring(4);
}
String[] contentUriPrefixesToTry = new String[]{
"content://downloads/public_downloads",
"content://downloads/my_downloads",
"content://downloads/all_downloads"
};
for (String contentUriPrefix : contentUriPrefixesToTry) {
Uri contentUri = ContentUris.withAppendedId(Uri.parse(contentUriPrefix), Long.valueOf(id));
try {
String path = getDataColumn(context, contentUri, null, null);
if (path != null) {
return path;
}
} catch (Exception ignored) {}
}
Error:
java.lang.SecurityException: Permission Denial: reading com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/719 from pid=4604, uid=10438 requires android.permission.ACCESS_ALL_DOWNLOADS, or grantUriPermission()
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
