简体   繁体   English

如何验证我的应用是否有 ALL_FILES_ACCESS_PERMISSION?

[英]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.

相关问题 如何知道该应用程序当前是否具有“所有文件访问权限”权限。 Android 11 - how to know whether the app currently has the 'All Files Access' permission or not. Android 11 如何检查应用程序是否在低端 Android 上具有 ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION 和其他存储权限 - How to check if app has ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION and other storage permissions on lower Androids 安卓应用的所有文件访问权限 - ALL FILE ACCESS permission for android app 如何在设备android上添加文件访问权限 - How to add files access permission on device android 如何访问另一个应用程序的权限屏幕? - How to access permission screen of another app? 当我只有一个目录的 uri 时,如何创建文件? (该目录的持久权限由 Android 用户授予。) - How do I create files when all I have is an uri of a directory? (Persistable permission for the directory was granted by the Android user.) 如何使用HQL / Hibernate验证我的所有表都为空? - How can i verify that all my tables are empty with HQL/Hibernate? 我怎样才能访问放在WEB-INF文件夹中的文件 - how can i have access to my files that placed in WEB-INF folder 如何访问通过App Engine应用存储的文件 - How to access files stored with App Engine app 如何授予CHMOD 0755对Jar中所有文件的权限 - How to give CHMOD 0755 permission to all files in a jar
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM