SecurityException:权限被拒绝ACCESS_ALL_DOWNLOADS [英] SecurityException: Permission Denial ACCESS_ALL_DOWNLOADS
问题描述
我正在尝试使用DownloadManager下载文件.是的,我知道人们已经收到此错误.但是我的似乎还没有解决.我每次都尝试过.
I am trying to download files using DownloadManager. Yes I know people already got this error. but mine does not seems to be resolved. I have tried everytime.
我已取消此权限:
<使用权限android:name ="android.permission.INTERNET"/>< uses-permission android:name ="android.permission.ACCESS_ALL_DOWNLOADS"/>< uses-permission android:name ="android.permission.WRITE_EXTERNAL_STORAGE"/>
我的代码
public void startDownload(String str) {
try {
MarshmellowPermissions permissions = new MarshmellowPermissions(context);
permissions.checkWriteExternalStoragePermission();
DownloadManager mManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
DownloadManager.Request mRqRequest = new DownloadManager.Request(Uri.parse(str));
mRqRequest.setDescription("This is Test File");
long idDownLoad = mManager.enqueue(mRqRequest);
mManager.remove(idDownLoad);
try {
mManager.openDownloadedFile(idDownLoad);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
此行出现错误
mManager.openDownloadedFile(idDownLoad);
这是错误日志:
java.lang.SecurityException:权限被拒绝:从pid = 3926读取com.android.providers.downloads.DownloadProvider uri content://downloads/all_downloads/15,uid = 10086需要android.permission.ACCESS_ALL_DOWNLOADS,或grantUriPermission()
推荐答案
看起来还没有人对此有一个答案,我已经解决了这个问题,并希望分享我的解决方法.因此,基本上,这是行不通的,因为我没有在运行时请求权限.
Look's like no one has an answer for this yet, I have already solved the issue and wanted to share how I solved it. So basically It wasn't working because I wasn't asking for permission on runtime.
我所做的是向运行时询问权限.在下面使用此代码.
What I did was ask the permission on runtime. Using this code below.
ActivityCompat.requestPermissions(MainActivity.this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
这篇关于SecurityException:权限被拒绝ACCESS_ALL_DOWNLOADS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!