gpt4 book ai didi

android - Android-并获得权限WRITE_SETTINGS ?!

转载 作者:行者123 更新时间:2023-11-29 18:59:55 25 4
gpt4 key购买 nike

我在获得许可时遇到问题,我似乎无法理解为什么我没有获得更改屏幕亮度的许可。

我的清单如下所示:

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


在我的活动中,它看起来像这样:

public void changeScreenBrightness(float brightness) {
mBrightness = brightness;

if(Settings.System.canWrite(this)) {
Intent perminssionIntent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
startActivity(perminssionIntent);

}else {
Settings.System.putInt(mContentResolver, Settings.System.SCREEN_BRIGHTNESS, (int) (mBrightness*255));
}

WindowManager.LayoutParams mLayoutParams = mWindow.getAttributes();
mLayoutParams.screenBrightness = mBrightness;
mWindow.setAttributes(mLayoutParams);
}


但是,该权限没有被授予?!谁能看到原因?

最佳答案

您尚未在!中包含if(Settings.System.canWrite(this)),则需要在canWrite(this)返回false时进入此分支。将您的功能更改为此,您的问题将得到解决。

public void changeScreenBrightness(float brightness) {
mBrightness = brightness;

if(!Settings.System.canWrite(this)) {
Intent perminssionIntent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
startActivity(perminssionIntent);

} else {
Settings.System.putInt(mContentResolver, Settings.System.SCREEN_BRIGHTNESS, (int) (mBrightness*255));
}

WindowManager.LayoutParams mLayoutParams = mWindow.getAttributes();
mLayoutParams.screenBrightness = mBrightness;
mWindow.setAttributes(mLayoutParams);
}

关于android - Android-并获得权限WRITE_SETTINGS ?!,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49296636/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com