简体   繁体   English

单击小部件后更改屏幕亮度。 安卓系统

[英]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 !! 此后,我的亮度值将更改为200,但实际上看不到任何差异! .. 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. 有没有办法强迫Android刷新整个屏幕,或者我错过了什么。 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: 没有MODE值200。您可能应该执行以下操作:


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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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