2015-05-28 107 views
0

您是否知道無法通過「Hi everyone」開始提問?即時觸發本地通知

大家好,

通知立即在第一次啓動時出現。以下是設置通知的代碼。它應該每天9點到10點出現。

Calendar calendar = Calendar.getInstance(); 
calendar.set(Calendar.HOUR_OF_DAY, hour); 
calendar.set(Calendar.MINUTE, minute); 
calendar.set(Calendar.SECOND, 0); 
Log.v("TIMETIME", "schedule reminder: " + hour + ":" + minute); 

Intent notificationIntent = new Intent(context, AlarmReceiver.class); 
notificationIntent.putExtra(AlarmReceiver.NOTIFICATION_ID, 1); 
notificationIntent.putExtra(AlarmReceiver.NOTIFICATION, getNotification(context)); 
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT); 
AlarmManager alarmManager = (AlarmManager)context.getSystemService(Context.ALARM_SERVICE); 
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent); 

在另一方面是報警廣播接收器

NotificationManager notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); 
Notification notification = intent.getParcelableExtra(NOTIFICATION); 
int id = intent.getIntExtra(NOTIFICATION_ID, 0); 
notificationManager.notify(id, notification); 

死的簡單,但不工作。

回答

0

我認爲問題在於日曆。 您可以調用設置的方法而不需要每天調整,因此很可能您正試圖設置一個已經過去的時間。