【问题标题】:How to Push Local Notification in android at some particular time when device is in sleep mode如何在设备处于睡眠模式时的某个特定时间在 android 中推送本地通知
【发布时间】:2016-08-18 10:20:51
【问题描述】:

实际上,我正在尝试制作我的大学常规应用程序..它使用 NotificationManager 向用户通知当前期间(我总共有九个期间,有些时间间隔不同)...一切正常,但问题是当设备进入睡眠状态时发生,它不会在睡眠模式下推送任何通知...我正在使用服务来推送通知,但我猜服务在睡眠模式下也会进入睡眠状态...我的服务在睡眠期间永远不会自动终止...但它没有给出任何通知...请帮助我

Click Here to view my code

【问题讨论】:

  • AndroidManifest.xml 中添加这个 ` `
  • 那太耗电了
  • 嘿,我遇到了类似的问题,但在我的情况下,这种行为是随机的。我在睡眠模式下收到通知一段时间,几分钟后通知就停止了。在按下锁定按钮时,它会再次启动。你找到解决办法了吗?

标签: java android android-studio push-notification notifications


【解决方案1】:

我使用广播接收器执行此操作我设置了每 60 秒重复广播一次

像这样:

Intent notificationIntent = new Intent(context,thebroadcastclass.class);
        notificationIntent.addCategory("android.intent.category.HIGH");
        broadcast = PendingIntent.getBroadcast(context.getApplicationContext(), 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, System.currentTimeMillis(),60000, broadcast);

工作正常,但间隔必须至少为 60 秒 (它会消耗太多电池)

这是广播接收器:

public class thebroadcastclass extends BroadcastReceiver {
    @Override
    public void onReceive(Context context, Intent intent) {
        toastmaker.update(context, intent);
    }}

希望你能用这个(:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-02-07
    相关资源
    最近更新 更多