0
我想在特定時間發送通知。以下是我的代碼。目前,我在啓動應用程序時只收到通知,但在指定時間沒有收到通知。你能幫我理解我做錯了什麼嗎?如何在特定時間發送通知?
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Trainieren sie jetzt!")
.setAutoCancel(true);
Intent resultIntent = new Intent(this, MainActivity2.class);
AlarmManager alarmManager =(AlarmManager)getSystemService(ALARM_SERVICE);
PendingIntent resultPendingIntent =
PendingIntent.getActivity(
this,
0,
resultIntent,
PendingIntent.FLAG_UPDATE_CURRENT);
Calendar cal = Calendar.getInstance();
cal.set(Calendar.HOUR_OF_DAY, 12);
cal.set(Calendar.MINUTE, 54);
alarmManager.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), 24*60*60*1000, resultPendingIntent);
mBuilder.setContentIntent(resultPendingIntent);
int mNotificationId = 001;
NotificationManager mNotifyMgr =
(NotificationManager) getSystemService(NOTIFICATION_SERVICE);
mNotifyMgr.notify(mNotificationId, mBuilder.build());
感謝您的幫助!
你必須設置通知,你正在設置時間... – Umair 2014-08-29 11:04:11
你真的想重複報警嗎? – Opiatefuchs 2014-08-29 11:04:56
根據我的想法,用廣播接收機設置重複報警不是一個瓶頸。只有定時器選項可能變得非常麻煩。如果喚醒鎖在服務中正確實施,則效率會更高。 – Skynet 2014-08-29 11:11:44