我想要一个每天重复的重复通知,但这段代码是我在create上的main activity中编写的,但第二天不会重复通知,只工作一天。
AlarmManager alarmManager1 = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent intent = new Intent(getApplicationContext(), Notification_Receiver.class);
intent.putExtra("title", "Prayer Time Intimation");
intent.putExtra("msg", "Time of Isha is About to End");
intent.putExtra("NOTIFhh", calendar.get(Calendar.HOUR_OF_DAY));
intent.putExtra("NOTIFmm", calendar.get(Calendar.MINUTE));
int id = endishaid;
intent.putExtra("notifyid", id);
PendingIntent pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), 101, intent, PendingIntent.FLAG_UPDATE_CURRENT);
pendingIntent = PendingIntent.getBroadcast(getApplicationContext(), id, intent, PendingIntent.FLAG_UPDATE_CURRENT);
alarmManager1.setInexactRepeating(AlarmManager.RTC_WAKEUP, calendar.getTimeInMillis(), AlarmManager.INTERVAL_DAY, pendingIntent);
阿拉姆经理班
public class Notification_Receiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
Uri alarmSound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
long[] pattern = {0, 100, 200, 300};
Notification notification = new NotificationCompat.Builder(context, CHANNEL_1_ID)
.setSmallIcon(android.R.drawable.arrow_up_float)
.setContentTitle(title)
.setContentText(msg)
.setStyle(new NotificationCompat.BigTextStyle()
.setBigContentTitle(title)
.setSummaryText(msg))
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setCategory(NotificationCompat.CATEGORY_MESSAGE)
.setSound(alarmSound)
.setVibrate(pattern)
.setColor(16753737)
.setLights(16753737, 300, 1000)
.setContentIntent(pendingIntent)
.setAutoCancel(true)
.setOnlyAlertOnce(true)
.build();
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
//NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
notificationManager.notify(createID(), notification);
}
暂无答案!
目前还没有任何答案,快来回答吧!