简体   繁体   English

android.permission.WRITE_SETTINGS 是否仅授予系统应用程序?

[英]Is android.permission.WRITE_SETTINGS only granted to system apps?

We are currently developing an app where we'd like to change some system settings, with user permission of course.我们目前正在开发一个应用程序,我们想在其中更改一些系统设置,当然需要用户许可。 The android documentation says that to do this, you have to add the following permission: android 文档说要做到这一点,您必须添加以下权限:

<uses-permission android:name="android.permission.WRITE_SETTINGS" />

Also, one has to explicitly ask the user to enable this permission.此外,必须明确要求用户启用此权限。 An excerpt from https://developer.android.com/reference/android/Manifest.permission#WRITE_SETTINGS says: https://developer.android.com/reference/android/Manifest.permission#WRITE_SETTINGS的摘录说:

Note: If the app targets API level 23 or higher, the app user must explicitly grant this permission to the app through a permission management screen.注意:如果应用针对 API 级别 23 或更高级别,应用用户必须通过权限管理屏幕显式授予应用此权限。 The app requests the user's approval by sending an intent with action Settings.ACTION_MANAGE_WRITE_SETTINGS .该应用程序通过发送带有操作Settings.ACTION_MANAGE_WRITE_SETTINGS的意图来请求用户的批准。 The app can check whether it has this authorization by calling Settings.System.canWrite() .该应用程序可以通过调用Settings.System.canWrite()来检查它是否具有此授权。

Up until this point, it is quite clear.到目前为止,一切都很清楚。 However, when the permission is added to the AndroidManifest.xml file, Android Studio complains that " Permission is only granted to system apps ".但是,当将权限添加到AndroidManifest.xml文件时,Android Studio 会抱怨“权限仅授予系统应用程序”。 Now, this is confusing since I haven't found any documentation stating that it is indeed only granted to system apps.现在,这令人困惑,因为我没有找到任何说明它确实只授予系统应用程序的文档。

So, I'd like to ask if someone has encountered this issue, and if there is some kind of documentation that explains this in detail?所以,我想问一下是否有人遇到过这个问题,是否有某种文档可以详细解释这个问题? Or am I simply missing something?还是我只是错过了什么?

As stated by user passsy in the stackoverflow question provided by Brian , android.permission.WRITE_SETTINGS has a android:protectionLevel of "signature" , which makes the permission unavailable for use in user applications since API level 23.正如用户passsyBrian提供的 stackoverflow 问题中所述, android.permission.WRITE_SETTINGS有一个android:protectionLevel of "signature" ,这使得权限在 ZDB974238714CA8DE634 级别后无法在用户应用程序中使用。

See https://developer.android.com/guide/topics/manifest/permission-element#plevel for the description of protection levels for permissions.有关权限保护级别的说明,请参见https://developer.android.com/guide/topics/manifest/permission-element#plevel

You need to get the user permission specifically from the user by that I mean you have to take the user to a screen where user can grant the permission to your app to have WRITE_SETTINGS permission.您需要专门从用户那里获得用户权限,我的意思是您必须将用户带到一个屏幕,用户可以在该屏幕上授予您的应用程序具有 WRITE_SETTINGS 权限的权限。

So when ever you want to change system settings you have to check if the user has granted the permission or not like this:因此,当您想要更改系统设置时,您必须检查用户是否已授予权限,如下所示:

private boolean checkSystemWritePermission() {
    boolean retVal = true;
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        retVal = Settings.System.canWrite(this);
        Log.d("TAG", "Can Write Settings: " + retVal);
        if(retVal){
            ///Permission granted by the user
        }else{
            //permission not granted navigate to permission screen
            openAndroidPermissionsMenu();
        }
    }
    return retVal;
}

private void openAndroidPermissionsMenu() {
    Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
    intent.setData(Uri.parse("package:" + this.getPackageName()));
    startActivity(intent);
 }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 com.android.shell没有获得此权限:android.permission.WRITE_SETTINGS - com.android.shell was not granted this permission: android.permission.WRITE_SETTINGS java.lang.SecurityException:未授予此权限:android.permission.WRITE_SETTINGS - java.lang.SecurityException: was not granted this permission: android.permission.WRITE_SETTINGS java.lang.SecurityException:未被授予此权限:android.permission.WRITE_SETTINGS 关闭对话框时 [Android] - java.lang.SecurityException: was not granted this permission: android.permission.WRITE_SETTINGS when Dismiss a Dialog [Android] android.permission.WRITE_SETTINGS错误 - android.permission.WRITE_SETTINGS error 权限拒绝:写入设置需要android.permission.WRITE_SETTINGS - Permission denial: writing to settings requires android.permission.WRITE_SETTINGS android.permission.WRITE_SETTINGS什么样的权限普通? 还是危险? - android.permission.WRITE_SETTINGS what kind of permission Normal? or Dangerous? 清单中不能使用android.permission.WRITE_SETTINGS - android.permission.WRITE_SETTINGS cant use in manifest 可以在android.permission.WRITE_SETTINGS或android.permission.WRITE_SECURE_SETTINGS中更改哪些设置? - What settings can be changed in android.permission.WRITE_SETTINGS or android.permission.WRITE_SECURE_SETTINGS? Android 6.0 权限拒绝:需要权限 android.permission.WRITE_SETTINGS - Android 6.0 Permission Denial: requires permission android.permission.WRITE_SETTINGS java.lang.SecurityException:Permission denial:写入设置需要android.permission.WRITE_SETTINGS - java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM