唤醒 Android 手机/平板电脑? [英] Wake up Android Phone/tablet?

查看:34
本文介绍了唤醒 Android 手机/平板电脑?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个推送通知应用,有什么办法可以在我收到推送通知时唤醒屏幕(只是让它亮起来)?

I've got a push notification-app, is there any way to wake up the screen (just make it light up) whenever I receive a push notification?

如果你想要一些代码,请告诉我!并感谢您的回答!

if you want some code just let me know! and Thank you for your answers!

推荐答案

您可以使用 WakeLock 这样做:

You can do it using a WakeLock this way:

当您设置通知时:

WakeLock screenOn = ((PowerManager)getSystemService(POWER_SERVICE)).newWakeLock(PowerManager.SCREEN_BRIGHT_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP, "example");
screenOn.acquire();

而且,重要,当您不再需要时释放唤醒锁:

And, IMPORTANT, release the wakelock when you don't need it anymore:

screenOn.release();

这篇关于唤醒 Android 手机/平板电脑?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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