Android写入系统设置对话框显示为灰色

时间:2017-06-25 21:04:45

标签: java android android-permissions

我想写入系统设置来更改屏幕亮度。 为此,我需要WRITE_SYSTEM_SETTINGS。 我在Android 7.1上

我称这可以打开一个让用户启用此权限的对话框。

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
   if (!Settings.System.canWrite(getApplicationContext())) {
      Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS, Uri.parse("package:" + getPackageName()));
      startActivityForResult(intent, 200);

     }
 }

对话框将打开,但打开权限的开关显示为灰色。 我做错了什么?

编辑AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.fimrc.mysensornetwork">

    <uses-permission android:name="android.permission.READ_CONTACTS" />
    <uses-permission android:name="android.permission.READ_CALENDAR" />
    <uses-permission android:name="android.permission.READ_PHONE_STATE" />
    <uses-permission android:name="android.permission.PROCESS_OUTGOING_CALLS" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.RECEIVE_SMS" />
    <uses-permission android:name="android.permission.READ_SMS" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <uses-permission android:name="android.permission.BATTERY_STATS" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT" />
    <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />

    <uses-feature android:name="android.hardware.location.gps" />
    <uses-feature android:name="android.hardware.location.network" />

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:supportsRtl="true"
        android:theme="@style/AppTheme">
        <activity
            android:name=".gui.MainActivity"
            android:launchMode="singleInstance">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <service android:name=".SensorService" />
        <service
            android:name=".PolicingService"
            android:enabled="true"
            android:exported="true" />

        <receiver
            android:name=".PolicingReceiver"
            android:enabled="true"
            android:exported="true" />

        <activity android:name=".gui.policing.PolicingActivity" />
        <activity android:name=".gui.old.QuestionnaireActivity" />
        <activity android:name=".gui.policing.PolicingRatingActivity" />
        <activity android:name=".gui.SensorSettingsActivity" />
        <activity android:name=".gui.QuestionnaireActivity"></activity>
    </application>

</manifest>

在我兄弟的手机上,可以启用此权限。他使用Android 6。

1 个答案:

答案 0 :(得分:3)

请添加:

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