[英]How to verify if my app have ALL_FILES_ACCESS_PERMISSION?
I give all files access by this method :我通过这种方法授予所有文件访问权限:
if (!hasPermissionToManageFiles(myContext)){
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R){
try {
Intent intentFiles = new Intent();
intentFiles.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
Uri uriFiles = Uri.fromParts("package", myContext.getPackageName(), null);
intentFiles.setData(uriFiles);
myContext.startActivity(intentFiles);
}
catch (Exception e){
Intent intentFiles = new Intent();
intentFiles.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
myContext.startActivity(intentFiles);
}
}
}
This line in my manifest :我的清单中的这一行:
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />
I tried to create method to verify this kind of permission but it's not working.我试图创建方法来验证这种权限,但它不起作用。 I don't have any error, when my app has the permission to access the intent still appears.
我没有任何错误,当我的应用程序有权访问意图时仍然出现。
here is my method :这是我的方法:
public static boolean hasPermissionToManageFiles(Context context) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
return ActivityCompat.checkSelfPermission(context, Manifest.permission.MANAGE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED;
}
return true;
}
根据文档,您应该使用Environment.isExternalStorageManager
方法而不是checkSelfPermission
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.