我有一项服务,应该唤醒设备并在收到意图时停止屏幕保护程序。任何想法如何实现?
在活动中,我通常会这样做:
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
或
getWindow().addFlags(android.view.WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
问题是我没有Window
在服务中。
答案 0 :(得分:0)
在接收器中
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_SCREEN_OFF);
intentFilter.addAction(Intent.ACTION_SCREEN_ON);
BroadcastReceiver screenOnOff = new BroadcastReceiver()
{
public static final String ScreenOff = "android.intent.action.SCREEN_OFF";
public static final String ScreenOn = "android.intent.action.SCREEN_ON";
public void onReceive(Context contex, Intent intent)
{
if (intent.getAction().equals(ScreenOff))
{
Log.e("Log", "Screen Off");
}
else if (intent.getAction().equals(ScreenOn))
{
Log.e("Log", "Screen On");
}
}
};