앱을 작성하고 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);
}
}
문제가 무엇인지 명확하게 설명해 주시겠습니까? 귀하의 예에서 귀하의 전화가 11시 10 분의 통지뿐만 아니라 2시 10 분의 통지도 놓쳤을뿐만 아니라 그 이유를 알고 싶습니까? – Brionius