Android - 并获得WRITE_SETTINGS的许可?!

时间:2018-03-15 10:10:22

标签: android screen android-permissions brightness

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

我的清单看起来像这样:

<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);
    }

但许可是否被授予?!任何人都可以看到原因吗?

1 个答案:

答案 0 :(得分:2)

!返回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); } 。将您的功能更改为此,您的问题将得到解决。

 {
     name: a,
     Age:b
 }