收到通知时,Android屏幕亮起 [英] Light up screen when notification received android

查看:961
本文介绍了收到通知时,Android屏幕亮起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一项服务,以使我的应用程序每小时发送一次通知.由于我的通知,我每小时都会听到声音和振动,因此效果很好,但我也希望我的通知也能照亮我的屏幕.但是当出现通知时,我无法打开屏幕.

I have a service running for my application to send notification every hour. This is working fine as i heard a sound and a vibration every hour because of my notification but i also want that my notification light up my screen as well. But i am unable to light up my screen when notification appears.

推荐答案

PowerManager pm = (PowerManager)context.getSystemService(Context.POWER_SERVICE);
boolean isScreenOn = pm.isScreenOn();
Log.e("screen on.................................", ""+isScreenOn);
if(isScreenOn==false)
{
    WakeLock wl = pm.newWakeLock(PowerManager.FULL_WAKE_LOCK |PowerManager.ACQUIRE_CAUSES_WAKEUP |PowerManager.ON_AFTER_RELEASE,"MyLock");
    wl.acquire(10000);
    WakeLock wl_cpu = pm.newWakeLock(PowerManager.PARTIAL_WAKE_LOCK,"MyCpuLock");

    wl_cpu.acquire(10000);
}

这篇关于收到通知时,Android屏幕亮起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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