current position:Home>App live source code, Android set system brightness

App live source code, Android set system brightness

2022-01-27 01:38:54 Cloudleopard network technology

app Live source ,Android Set the relevant code of system brightness implementation
First, you need to dynamically apply for and modify the system setting permission

    if (!Settings.System.canWrite(DisplaySettingActivity.this)) {
    
        Intent intent = new Intent(Settings.ACTION_MANAGE_WRITE_SETTINGS);
        intent.setData(Uri.parse("package:" + DisplaySettingActivity.this.getPackageName()));
        intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        DisplaySettingActivity.this.startActivity(intent);
    } else {
    
        //  Operation after applying for permission 
        

    }
}

The value of brightness is generally 0~255
Get current brightness :

   /** *  Get the system default screen brightness value   Screen brightness value range (0-255) **/
    private int getScreenBrightness(Context context) {
    
        ContentResolver contentResolver = context.getContentResolver();
        int defVal = 125;// The default value returned when no value is obtained 
        return Settings.System.getInt(contentResolver,
                Settings.System.SCREEN_BRIGHTNESS, defVal);
    }

Get the maximum brightness :

Settings.System.getInt(getContentResolver(),Settings.System.SCREEN_BRIGHTNESS)

Set brightness :

/** *  modify Setting  Medium screen brightness value  * * **/
private void ModifySettingsScreenBrightness(Context context,
                                            int birghtessValue) {
    
    //  First, it needs to be set to manual screen brightness adjustment mode 
    setScreenManualMode(context);

    ContentResolver contentResolver = context.getContentResolver();
    Settings.System.putInt(contentResolver,
            Settings.System.SCREEN_BRIGHTNESS, birghtessValue);
}

That's all app Live source ,Android Set the relevant code of system brightness implementation , More content welcome to follow the article

copyright notice
author[Cloudleopard network technology],Please bring the original link to reprint, thank you.
https://en.cdmana.com/2022/01/202201270138517944.html

Random recommended