未显示WRITE_EXTERNAL_STORAGE的权限对话框 [英] Permission dialog is not shown for WRITE_EXTERNAL_STORAGE
问题描述
我要使用DownloadManager
下载文件.并且DownloadManager
想要WRITE_EXTERNAL_STORAGE
权限.
我在AndroidManifest.xml
中包含了WRITE_EXTERNAL_STORAGE
权限.此外,我尝试在运行时获得此权限.
I want to download a file using DownloadManager
. And DownloadManager
wants to WRITE_EXTERNAL_STORAGE
permission.
I have included the WRITE_EXTERNAL_STORAGE
permission in AndroidManifest.xml
. Furthermore, I try to take this permission on runtime.
onRequestPermissionsResult回调.没有显示请求权限弹出窗口.
onRequestPermissionsResult callback is called immediately after the request permission. The request permission popup didn't display.
但是,在onRequestPermissionsResult
上grantResult[0]
的值是 PERMISSION_DENIED .但是权限弹出式窗口"没有显示.
However, the value of the grantResult[0]
on the onRequestPermissionsResult
is PERMISSION_DENIED. But THE PERMISSION POPUP ISN'T EVEN SHOWN.
我这样检查权限:
public boolean isStoragePermissionGranted() {
if (Build.VERSION.SDK_INT >= 23) {
if (checkSelfPermission(getContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
Log.v(TAG,"Permission is granted");
return true;
} else {
Log.v(TAG,"Permission is revoked");
ActivityCompat.requestPermissions(getActivity(), new String[]{android.Manifest.permission.WRITE_EXTERNAL_STORAGE}, WRITE_EXTERNAL_PERMISSION_REQUEST_CODE);
return false;
}
}
else {
Log.v(TAG,"Permission is granted");
return true;
}
}
这是权限请求的回调:
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
switch (requestCode) {
case WRITE_EXTERNAL_PERMISSION_REQUEST_CODE: {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
downloadFile();
}
break;
}
}
}
当我尝试使用READ_EXTERNAL_STORAGE
权限时,我可以获取该权限,但对于WRITE_EXTERNAL_STORAGE
权限却无效.
When I have tried for READ_EXTERNAL_STORAGE
permission, I could take that permission but it didn't work for WRITE_EXTERNAL_STORAGE
permission.
我也尝试过 @MetaSnarf的解决方案.但是什么都没有改变.
Also, I have tried @MetaSnarf's solution. But nothing has changed.
您对这种情况有任何想法吗?
Have you any idea about this situation?
推荐答案
您的一个依赖项可能会导致该问题.您可以在清单中替换权限.
One of your dependency can cause that problem. You can replace permission in your manifest.
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" tools:node="replace" />
这篇关于未显示WRITE_EXTERNAL_STORAGE的权限对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!