计时器触发后唤醒Android屏幕 [英] Wake the Android Screen after a timer fires
本文介绍了计时器触发后唤醒Android屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何让计时器触发一种方法来唤醒Android设备的屏幕?
How can I have a timer fire a method to wake up the screen of an Android device?
我插入了这个
final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
| WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);
win.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
| WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);
进入
@Override
protected void onCreate(Bundle savedInstanceState) {
方法.
此外,我在用户单击运行以下程序的按钮后设置了计时器:
Additionally, I made a timer after a user clicks a button which runs the following program:
final int interval = 3000; // 3 Seconds
Handler handler = new Handler();
Runnable runnable = new Runnable(){
public void run() {
Toast.makeText(getApplicationContext(), "Here", Toast.LENGTH_SHORT).show();
}
};
handler.postAtTime(runnable, System.currentTimeMillis()+interval);
handler.postDelayed(runnable, interval);
我希望能够单击我的Android设备的电源按钮使其在3秒的间隔内进入睡眠状态,并在run()触发后将其唤醒. 我叫什么来触发屏幕打开?
I want to be able to click the power button of my Android device to sleep it within the 3 second interval and have it wake up after the run() gets fired. What do I call to trigger the screen to turn on?
推荐答案
此方法也会立即在屏幕上打开:
This method also instantly turns on the screen:
PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock TempWakeLock = powerManager.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK|PowerManager.ACQUIRE_CAUSES_WAKEUP, "TempWakeLock");
TempWakeLock.acquire();
TempWakeLock.release();
这篇关于计时器触发后唤醒Android屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文