简体   繁体   中英

Change screen brightness after click on widget. Android

I've done what's in here and it works except it's not. I mean my phone says "yeah .. my brightness changed" but I can't see any differences at all.

After click on widget, I'm calling this Receiver:

public class Brightness extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    Intent myIntent = new Intent(context, RefreshClass.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, myIntent, 0);
    try {
        pendingIntent.send(context, 0, myIntent);
    } catch (CanceledException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}

Then:

public class RefreshClass extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    try {
        int curBrightnessValue = android.provider.Settings.System.getInt(getContentResolver(),
                android.provider.Settings.System.SCREEN_BRIGHTNESS);
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE,
                200);
        Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS, 200);

        WindowManager.LayoutParams lp = getWindow().getAttributes();
        lp.screenBrightness = 200;
        getWindow().setAttributes(lp);

    } catch (SettingNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    finish();
}

}

After this my brightness value is changing to 200 but I can't see any difference actually BUT !! .. after turns my screen of and on screen is refreshing and the brightness is changing then just like it should be. Is there any way to force android to refresh whole screen like this or maybe im missing something. help!

This line in your sample is probably wrong:


Settings.System.putInt(getContentResolver(),  Settings.System.SCREEN_BRIGHTNESS_MODE,  200);

There is no MODE value 200. You should probably do something like this:


Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_BRIGHTNESS_MODE, Settings.System.SCREEN_BRIGHTNESS_MODE_MANUAL);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM