简体   繁体   English

如何检查应用程序是否在低端 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

Is there a way to check if my device already has the following permissions with one line or how should I check this?有没有办法通过一行来检查我的设备是否已经具有以下权限,或者我应该如何检查?

I am supporting SDK versions from 21 to 30 so I cannot use :我支持从 21 到 30 的 SDK 版本,所以我不能使用:

if (!Environment.isExternalStorageManager()) {

Because it requires API level 30, but my min is 21.因为它需要 API 级别 30,但我的最小值是 21。

This is how I am asking for permissions:这就是我请求权限的方式:

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
        try {

            Uri uri = Uri.parse("package:" + BuildConfig.APPLICATION_ID);
            Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri);
            intent.addCategory("android.intent.category.DEFAULT");
            intent.setData(Uri.parse(String.format("package:%s", getApplicationContext().getPackageName())));
            startActivityForResult(intent, 2296);
        } catch (Exception ex){
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
            startActivity(intent);
        }
    } else {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
    }
}

So is there a permission check that would work for all of these?那么是否有适用于所有这些的权限检查?

The answer for me here was to change Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q to Build.VERSION.SDK_INT > Build.VERSION_CODES.Q and then check permission with !Environment.isExternalStorageManager() .我的答案是将Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q更改为Build.VERSION.SDK_INT > Build.VERSION_CODES.Q ,然后使用!Environment.isExternalStorageManager()检查权限。

if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
    if(!Environment.isExternalStorageManager()){
        try {
            Uri uri = Uri.parse("package:" + BuildConfig.APPLICATION_ID);
            Intent intent = new Intent(Settings.ACTION_MANAGE_APP_ALL_FILES_ACCESS_PERMISSION, uri);
            intent.addCategory("android.intent.category.DEFAULT");
            intent.setData(Uri.parse(String.format("package:%s", getApplicationContext().getPackageName())));
            startActivity(intent);
        } catch (Exception ex){
            Intent intent = new Intent();
            intent.setAction(Settings.ACTION_MANAGE_ALL_FILES_ACCESS_PERMISSION);
            startActivity(intent);
        }
    }
} else {
    if(ActivityCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) {
        ActivityCompat.requestPermissions(this, new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE}, 100);
    }
}

暂无
暂无

声明:本站的技术帖子网页,遵循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 如何验证我的应用是否有 ALL_FILES_ACCESS_PERMISSION? - How to verify if my app have ALL_FILES_ACCESS_PERMISSION? 安卓应用的所有文件访问权限 - ALL FILE ACCESS permission for android app Android MANAGE_EXTERNAL_STORAGE 权限被 Google Playstore 拒绝用于社交网络应用 - Android MANAGE_EXTERNAL_STORAGE permission reject by Google playstore for social networking app 如何在不使用管理外部存储权限的情况下在 android 11 范围存储中获取手机存储中可用的所有 pdf 文件 - how to get all pdf file available in my phone storage in android 11 scope storage without using manage external storage permission 创建没有管理所有文件权限的目录 - Create directory without manage all files permission 如何访问另一个应用程序的权限屏幕? - How to access permission screen of another app? 不能访问其他应用程序创建的外部存储中的文件 - Not abe to access file in External Storage created by other app 如何访问通过App Engine应用存储的文件 - How to access files stored with App Engine app SIP注册失败-超时-清单中包含的所有权限,但APP中未包含来自互联网许可的接收数据 - SIP registration fails - TIME OUT - ALL PERMISSIONS included in the manifest BUT the RECEIVE DATA FROM INTERNET PERMISSION not included in the APP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM