为什么我的电话下车后我的常规通知会停止?

时间:2013-08-11 01:21:52

标签: java android alarmmanager

我写了一个应用程序并设置了一个警报管理器,它每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);

}

}

1 个答案:

答案 0 :(得分:0)

我不太了解以下部分:

  

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

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

Android: make notification persist across phone reboot

android notification after reboot

Android: why did the Alarm notification stop after system reboot

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