我的日食中有2个应用程序,它们都称为方法
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
但是一个工作正常,其他工作根本不起作用(屏幕仍然会在一段时间后完全变暗,并且出现锁定屏幕)。我使用的代码完全相同,我很沮丧为什么它不适用于第二个应用程序。任何人都知道这是怎么回事?
以下是我的第二个应用的代码:
private void DimScreen() //isDim is false initially
{
Log.i(TAG, "isDim"+String.valueOf(isDim));
SharedPreferences pref = getSharedPreferences(null, 0);
String enableDim = pref.getString("enableDimScreen", "true"); //default preference is true(to dim screen)
Log.i(TAG, "inside Dimscreen(), enableDim="+enableDim);
if(enableDim.equals("true")&&!isDim) //if the user want to dim the screen
{
Toast.makeText(StartActivity.this, "Dimming screen in 5 seconds, press Stop button to turn on the screen", Toast.LENGTH_SHORT).show();
handler.postDelayed(r, 5000);
}
else {
if(!isDim) //if the user doesn't want to dim the screen
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
isDim =true;
Log.i(TAG, "inside Dimscreen() else");
}
}
}
private Handler handler= new Handler();
Runnable r = new Runnable()
{
public void run()
{
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.screenBrightness=0.01f;
getWindow().setAttributes(lp);
isDim =true;
Log.i(TAG, "isDim "+String.valueOf(isDim));
}
};
编辑: 我在我想要在第二个应用程序上调暗的活动上运行了chrome meter和进度条。