应用程序在睡眠模式下不通知本地通知

发布于 2024-12-17 04:24:33 字数 132 浏览 2 评论 0原文

我有一个任务是开发带有本地推送通知的android应用程序。我也为此开发了应用程序,但有时当用户设备处于睡眠模式时,它无法在用户设备上发出通知。

他们是否有任何代码来执行应用程序并在我的设备处于睡眠模式时通知我。请提供任何示例或来源。

I have a task to develop the android application with local push notification. I have also developed the application for that but some times when the user device is in sleep mode it can't notifying on the user device.

Is their any code to execute the application and notify me while my device is in sleep mode.Please provide any example or source for it.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

沒落の蓅哖 2024-12-24 04:24:33

您可能应该获取唤醒锁,如下所示:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl =  pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "My Tag");
 wl.acquire();
  ///  ..screen will stay on during this section..
 wl.release();

ACQUIRE_CAUSES_WAKEUP

正常的唤醒锁实际上不会打开照明。相反,它们会导致照明在打开后保持打开状态(例如,由于用户活动)。当获取 WakeLock 时,此标志将强制屏幕和/或键盘立即打开。典型用途是对于用户立即看到很重要的通知。

You're probably should be acquiring a wake lock, like so :

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
PowerManager.WakeLock wl =  pm.newWakeLock(PowerManager.FULL_WAKE_LOCK | PowerManager.ACQUIRE_CAUSES_WAKEUP
            | PowerManager.ON_AFTER_RELEASE, "My Tag");
 wl.acquire();
  ///  ..screen will stay on during this section..
 wl.release();

ACQUIRE_CAUSES_WAKEUP

Normal wake locks don't actually turn on the illumination. Instead, they cause the illumination to remain on once it turns on (e.g. from user activity). This flag will force the screen and/or keyboard to turn on immediately, when the WakeLock is acquired. A typical use would be for notifications which are important for the user to see immediately.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文