SCREEN_BRIGHTNESS_MODE 未经许可无法使用
SCREEN_BRIGHTNESS_MODE does not work with permission
在我的应用程序中,我想更改 SCREEN_BRIGHTNESS_MODE
(并设置另一个值)。我在 AndroidManifest.xml 中添加了权限(仔细检查了文件中的其他参数)。当按下按钮时,模式的值应该改变。
@Override
public void onClick(View v) {
if(on) {
ContentResolver cResolver = getContentResolver();
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, 50);
}
}
以及 AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Android 设备是逻辑仪器 Fieldbook F1 Android-版本 5.0.1
当我尝试执行此命令时出现以下异常:
08-31 15:29:28.471 16613-16613/com.matodayu.oxo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.matodayu.oxo, PID: 16613 java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS
at android.os.Parcel.readException(Parcel.java:1540)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:643)
at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1094)
at android.provider.Settings$System.putStringForUser(Settings.java:1371)
at android.provider.Settings$System.putIntForUser(Settings.java:1476)
at android.provider.Settings$System.putInt(Settings.java:1470)
at com.matodayu.oxo.FullscreenActivity.run(FullscreenActivity.java:184)
at android.app.Activity.runOnUiThread(Activity.java:5285)
at com.matodayu.oxo.FullscreenActivity.onClick(FullscreenActivity.java:179)
at android.view.View.performClick(View.java:4809)
at android.view.View$PerformClick.run(View.java:20123)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5534)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
谁能帮帮我?
你在哪里定义你的权限?
在清单或应用程序标签内?
我制作了一个测试项目并且它有效。
当我在错误的位置添加权限时它就失败了 - 例如应用程序标签。
在我的应用程序中,我想更改 SCREEN_BRIGHTNESS_MODE
(并设置另一个值)。我在 AndroidManifest.xml 中添加了权限(仔细检查了文件中的其他参数)。当按下按钮时,模式的值应该改变。
@Override
public void onClick(View v) {
if(on) {
ContentResolver cResolver = getContentResolver();
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);
Settings.System.putInt(cResolver, Settings.System.SCREEN_BRIGHTNESS, 50);
}
}
以及 AndroidManifest.xml:
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<activity
android:name=".FullscreenActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:label="@string/app_name"
android:screenOrientation="landscape"
android:theme="@style/FullscreenTheme">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.HOME" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
Android 设备是逻辑仪器 Fieldbook F1 Android-版本 5.0.1
当我尝试执行此命令时出现以下异常:
08-31 15:29:28.471 16613-16613/com.matodayu.oxo E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.matodayu.oxo, PID: 16613 java.lang.SecurityException: Permission denial: writing to settings requires android.permission.WRITE_SETTINGS
at android.os.Parcel.readException(Parcel.java:1540)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:190)
at android.database.DatabaseUtils.readExceptionFromParcel(DatabaseUtils.java:142)
at android.content.ContentProviderProxy.call(ContentProviderNative.java:643)
at android.provider.Settings$NameValueCache.putStringForUser(Settings.java:1094)
at android.provider.Settings$System.putStringForUser(Settings.java:1371)
at android.provider.Settings$System.putIntForUser(Settings.java:1476)
at android.provider.Settings$System.putInt(Settings.java:1470)
at com.matodayu.oxo.FullscreenActivity.run(FullscreenActivity.java:184)
at android.app.Activity.runOnUiThread(Activity.java:5285)
at com.matodayu.oxo.FullscreenActivity.onClick(FullscreenActivity.java:179)
at android.view.View.performClick(View.java:4809)
at android.view.View$PerformClick.run(View.java:20123)
at android.os.Handler.handleCallback(Handler.java:815)
at android.os.Handler.dispatchMessage(Handler.java:104)
at android.os.Looper.loop(Looper.java:194)
at android.app.ActivityThread.main(ActivityThread.java:5534)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:955)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:750)
谁能帮帮我?
你在哪里定义你的权限? 在清单或应用程序标签内?
我制作了一个测试项目并且它有效。 当我在错误的位置添加权限时它就失败了 - 例如应用程序标签。