在屏幕上的Andr​​oid转 [英] Android turn on the screen

查看:137
本文介绍了在屏幕上的Andr​​oid转的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我做一项活动推出由AlarmManager计划中的应用。我想,即使画面被关闭,装置被锁定到出现

I making the application where an activity launch is scheduled by AlarmManager. I would like to appear even if the screen is turned off and device is locked.

为了更好地实现这个设置窗口标志

To achive this a set the Window flags

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
        | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);

和尝试获取锁屏

if(_lock == null)
{
    PowerManager pm = (PowerManager)App.getAppContext()
            .getSystemService(Context.POWER_SERVICE);

    _lock = pm.newWakeLock(
            PowerManager.FULL_WAKE_LOCK, "ScreenOn");
    _lock.acquire();
}

的_lock是其在的onPause释放PowerManager.WakeLock

The _lock is PowerManager.WakeLock which is released in onPause

protected void onPause()
{
     if(_lock != null)
     {
          _lock.release();
     }
}

这code是的onCreate和onRestart执行。如果该活动尚未启动,一切工作正常。

This code is executed in onCreate and onRestart. Everything works OK if the activity is not launched yet.

但如果是早期推出的屏幕不被关闭。

But if it was launched earlier the screen is not turned off.


  • onRestart首次调用

  • 然后onResume被称为

  • 的onPause立即调用

所以,该活动不会启动。我的问题是如何把在这样的情况下在屏幕上。 (我用API 15)。

So the activity is not launched. My question is how to turn on the screen in such situation. (I am using API 15).

推荐答案

只需使用您的code:

Just use your code :

final Window win = getWindow();
win.addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
        | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD);

的onCreate()只并删除所有其他活动周期的方法,如果他们没有做别的事情,然后这一点。

in onCreate() only and remove all those other Activity-Cycle methods if they are not doing anything else then this.

我不认为你需要更多的code用来执行它。

I don't think you need any more code to use to perform it.

这篇关于在屏幕上的Andr​​oid转的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆