0

我编写了一个应用程序并设置了一个警报管理器,该管理器设置为每 3 小时发送一次通知。假设我的通知必须在 11:10 发送,而我的手机在 11:00 下车。所以,我不会收到任何通知。当我的手机打开时,我会在 2:10 收到下一个通知,所以一切正常。

虽然,据观察,我的手机在两轮通知下机后不会收到任何通知。你有什么建议吗?

提供代码:

Intent intentAlarm = new Intent(this, NotifyBroadcast.class);
                      PendingIntent pintentAlarm = PendingIntent.getBroadcast(this, 0, intentAlarm, PendingIntent.FLAG_CANCEL_CURRENT);
                      AlarmManager mgr = (AlarmManager)getSystemService(Context.ALARM_SERVICE);
                      // Start every 30 seconds
                      mgr.setRepeating(AlarmManager.RTC_WAKEUP, Calendar.getInstance().getTimeInMillis(), 300, pintentAlarm);


// NotifyBroadcast:


public  class NotifyBroadcast extends BroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub




    NotificationManager mNotificationManager =
            (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);


            Intent resultIntent = new Intent(context, MainActivity.class);


            PendingIntent resultPendingIntent =
                    PendingIntent.getActivity(
                    context,
                    0,
                    resultIntent,
                    0
                ); 



            Notification notification = new Notification(R.drawable.ic_launcher, "Let me know what is your emotion buddy!", System.currentTimeMillis());
            notification.defaults |= Notification.DEFAULT_SOUND;
            notification.sound = Uri.parse("file:///sdcard/notification/notification.mp3");
            //notification.flags = Notification.FLAG_AUTO_CANCEL;

            notification.setLatestEventInfo(context, "emotion interface", "Let me know what is your emotion buddy!", resultPendingIntent);



            int mId = 001;
            // mId allows you to update the notification later on.
            mNotificationManager.notify(mId, notification); 
          //  mNotificationManager.notify(mId,mBuilder.build());

            // mNotificationManager.cancel(mId);

}

}

4

1 回答 1

0

我不太了解以下部分:

I will not receive any notification after my phone is getting off for two round of notification.

只需检查您是否在重新启动后重新启动服务。为此,您需要添加一个接收器,在重新启动后再次启动您的服务。您需要在 android.intent.action.BOOT_COMPLETED意图广播时处理它。一些可能对您有帮助的问题是:

Android:让通知在手机重启后持续存在

重启后的android通知

Android:为什么系统重启后警报通知停止

希望这在某种程度上有所帮助。

于 2013-08-11T02:01:59.663 回答