什么是正确的,pcated非德$ P $的方式来唤醒设备? [英] what is the proper, non-deprecated way to wake up the device?

查看:211
本文介绍了什么是正确的,pcated非德$ P $的方式来唤醒设备?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的要求是:一个 GCM 消息到达后,该装置应该觉醒为显示一个高优先级的通知。该设备的应该打开屏幕的。

My requirement is: after a GCM message arrives, the device should wake up to display a high-priority notification. The device should turn the screen on.

目前我使用的是 WakeLock 以实现这一目标。该 newWakeLock()方法需要的锁级别和一个标志传递(作为第1个参数,按位或运算)。

Currently I'm using WakeLock to achieve this. The newWakeLock() method expects a lock level AND a flag to be passed (as the 1st param, bitwise or'd).

我用 PowerManager.ACQUIRE_CAUSES_WAKEUP 标记,因为它不正是我需要的。不过,我有点沮丧的锁定级别。因此,根据文档,我得到了以下选项:

I'm using PowerManager.ACQUIRE_CAUSES_WAKEUP flag since it does exactly what I need. However, I'm a bit frustrated about the lock level. So according to the docs, I got the following options:

  • PARTIAL_WAKE_LOCK - 以 ACQUIRE_CAUSES_WAKEUP /不兼容不打开屏幕
  • SCREEN_DIM_WAKE_LOCK - 德precated
  • SCREEN_BRIGHT_WAKE_LOCK - 德precated
  • FULL_WAKE_LOCK - 德precated
  • PARTIAL_WAKE_LOCK - not compatible with ACQUIRE_CAUSES_WAKEUP / doesn't turn the screen on
  • SCREEN_DIM_WAKE_LOCK - deprecated
  • SCREEN_BRIGHT_WAKE_LOCK - deprecated
  • FULL_WAKE_LOCK - deprecated

建议的 FLAG_KEEP_SCREEN_ON 在这种情况下完全无用。我最终只是苏pressing去precation警告:

The suggested FLAG_KEEP_SCREEN_ON is completely useless in this scenario. I ended up just supressing the deprecation warning:

@SuppressWarnings("deprecation")
PowerManager.WakeLock screenOn = ((PowerManager) c.getSystemService(Context.POWER_SERVICE)).newWakeLock(
PowerManager.SCREEN_DIM_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, TAG);
screenOn.acquire();
mNotifyMgr.notify(mNotificationId, mBuilder.build());
screenOn.release();

问题:有没有非去precated可靠的方式中所描述的情况下唤醒设备

The question: is there a non-deprecated reliable way to wake up the device in the described case?

修改我不要求寻求解决方法来唤醒设备。我的问题是的这是否可以唤醒从后台设备(无需运行活动)使用无德precated的API

EDIT I'm not asking for workarounds to wake up the device. My question is whether this is possible to wake up the device from the background (without a running Activity) using no deprecated APIs

推荐答案

使用code,我从我的问题了,然后​​就结束的活动,应在屏幕上留下了用户的时间正常量。相信我,这是唯一的办法,对这个问题的好花一周之后。你总是可以设置活动透明,notitlebar,用户将永远不会知道。

Use the code I got from my question, and then just finish the activity, should leave the screen on for the users normal amount of time. Trust me this is the only way, after spending a good week on this problem. You could always set the activity to transparent with notitlebar, the user will never know.

      @Override
        protected void onCreate(Bundle savedInstanceState) {
          getWindow().addFlags(WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD | WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON | WindowManager.LayoutParams.FLAG_ALLOW_LOCK_WHILE_SCREEN_ON);
          finish();
    }

这篇关于什么是正确的,pcated非德$ P $的方式来唤醒设备?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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