[英]notification not repeating
我為我的應用程序創建了一個通知。 它在正確的時間推送就可以正常工作,並且在按下時鏈接到正確的活動。
但是,我用重復的警報來稱呼它是因為我希望它在特定的日子里發射出去。 在我的初始測試中,我將其設置為每5秒按下一次,以便可以快速檢查它是否正確重復。 初次推送后,一旦我清除它,該通知就不會再出現。
這是我設置alarmManager的主要活動中的代碼:
private void notificationAlarm() {
Calendar cal = Calendar.getInstance();
cal.set(Calendar.DAY_OF_WEEK, 1);
cal.set(Calendar.HOUR, 1);
cal.set(Calendar.MINUTE, 40);
cal.set(Calendar.SECOND, 0);
cal.set(Calendar.MILLISECOND, 0);
long interval = cal.getTimeInMillis()+5000;
Intent alarmIntent = new Intent(this, alarmNotif.class);
PendingIntent alarmPendingIntent = PendingIntent.getBroadcast(this, 0, alarmIntent, PendingIntent.FLAG_ONE_SHOT);
AlarmManager notifAlarm = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
//notifAlarm.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), alarmPendingIntent);
notifAlarm.setRepeating(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), interval, alarmPendingIntent);
}
以及我的broadcastreceiver中的代碼:
公共類AlarmNotif擴展了BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
NotificationManager notifManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String title = "Don't forget to order sushi from Arbuckle!";
String subTitle = "Order before 10 AM with Arbuckle App";
Intent notifIntent = new Intent(context, SecureAppStarter.class);
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, notifIntent, PendingIntent.FLAG_ONE_SHOT);
NotificationCompat.Builder notifBuilder = new NotificationCompat.Builder(context)
.setContentTitle(title)
.setContentText(subTitle)
.setSmallIcon(R.drawable.ic_launcher)
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent);
Notification notif = notifBuilder.getNotification();
notifManager.notify(1, notif);
}
}
好吧,我想通了。
問題是FLAG_ONE_SHOT; 它應該是FLAG_UPDATE_CURRENT。
這允許以期望的間隔重復通知。
瞧!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.