2013-08-11 1 views
0

앱을 작성하고 3 시간마다 알림을 보내도록 설정된 알람 관리자를 설정했습니다. 11시 10 분에 알림을 보내야하고 11시에 전화가 내려와야한다고 가정합니다. 그래서, 나는 어떤 통보도받지 않을 것이다. 휴대 전화가 켜지면 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); 

} 

}

+0

문제가 무엇인지 명확하게 설명해 주시겠습니까? 귀하의 예에서 귀하의 전화가 11시 10 분의 통지뿐만 아니라 2시 10 분의 통지도 놓쳤을뿐만 아니라 그 이유를 알고 싶습니까? – Brionius

답변

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

희망.

관련 문제