【问题标题】:Alarm doesn't trigger notification after turning of device Android关闭设备 Android 后警报不会触发通知
【发布时间】:2012-11-29 17:28:39
【问题描述】:

在我的应用程序中,我需要设置闹钟,并在状态栏中显示通知。 我将预定事件存储在数据库中,并在通知出现时删除事件。

当我关闭设备并再次打开时。 base 中的列表存在,但永远不会触发警报事件。 当我关闭设备时,挂起的事件似乎被取消了。

如何预防? 我需要在设备开启时显示通知,并且警报时间到了。

这是我设置闹钟的方式:

    Intent intent = new Intent(activity, TimeAlarm.class);
    intent.putExtra(SHOW_NAME, showName);
    intent.putExtra(SHOW_START_TIME, showStartTime);
    intent.putExtra(CHANNEL_NAME, channelName);
    intent.putExtra(VIBRATION_ENABLED, isVibrate);
    intent.putExtra(SOUND_ENABLED, isSound);

    int alarmId = (int) System.currentTimeMillis();

    intent.putExtra(ALARM_ID, alarmId);

    PendingIntent pendingIntent = PendingIntent.getBroadcast(activity,
            alarmId, intent, PendingIntent.FLAG_ONE_SHOT);

    am.set(AlarmManager.RTC_WAKEUP,
            System.currentTimeMillis() + delayMilis, pendingIntent);

在清单文件中我只有这个:

 <receiver
        android:name="com.moleandroid.tvprogramgui.alarm.TimeAlarm"
 /receiver>

TimeAlarm 类是我的接收器,从那里我在状态栏中显示通知。

知道有什么问题吗?

【问题讨论】:

  • 设置标志为 PendingIntent.FLAG_UPDATE_CURRENT

标签: android alarmmanager


【解决方案1】:

您需要执行以下操作来解决此问题。通常当设备关闭时,它会取消警报的所有pendingIntent,因此在设备再次打开时它不会触发。警报应用程序在内部执行的操作是,当设备关闭/打开时,它将启动服务以注册事件

参考此链接以在代码中实现关机和开机意图。因此,当设备开机时,将所有事件安排到 AlarmManager,我相信这会起作用

Is there any way to receive a notification when the user powers off the device?

【讨论】:

  • 这很有意义...我会尝试这种方式。我只需要启动接收器。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2015-07-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多