[英]notification not repeating
I built a notification for my app. 我为我的应用程序创建了一个通知。 It's working, in the sense that it pushes at the correct time, and it links to the correct activity when pressed.
它在正确的时间推送就可以正常工作,并且在按下时链接到正确的活动。
However, I call it with a repeating alarm because I want it to shoot out on specific days. 但是,我用重复的警报来称呼它是因为我希望它在特定的日子里发射出去。 In my initial test, I set it to push every 5 seconds so I can check quickly that it is repeating correctly.
在我的初始测试中,我将其设置为每5秒按下一次,以便可以快速检查它是否正确重复。 After the initial push, once I clear it, the notification never reappears.
初次推送后,一旦我清除它,该通知就不会再出现。
Here is my code in my main activity to set up the alarmManager: 这是我设置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);
}
and the code inside my broadcastreceiver: 以及我的broadcastreceiver中的代码:
public class alarmNotif extends 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);
}
} }
Well I figured it out. 好吧,我想通了。
The problem was FLAG_ONE_SHOT; 问题是FLAG_ONE_SHOT; it should be FLAG_UPDATE_CURRENT.
它应该是FLAG_UPDATE_CURRENT。
This allows the notification to be repeated at the desired intervals. 这允许以期望的间隔重复通知。
Voila! 瞧!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.