我希望从设置之日起每周进行一次通知。它在被调用时初始化,但不是第二次。(我快速转发电话时钟以查看它是否会调用它,但它没有)。它必须是 7*calendar.getTimeInMillis()。我还能如何将其设置为每周一次?
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.HOUR_OF_DAY, mHour);
calendar.set(Calendar.MINUTE, mMinute);
AlarmManager am = (AlarmManager) getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, OnBootReceiver.class);
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_ONE_SHOT);
//am.set(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), pendingIntent);
am.setRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), 7*calendar.getTimeInMillis(), pendingIntent);
广播接收器类:
nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
CharSequence from = "from";
CharSequence message = "message";
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0);
Notification notif = new Notification(icon, tickerText, when);
notif.setLatestEventInfo(context, from, message, contentIntent);
nm.notify(1, notif);