java - Android中的通知不重复
问题描述
我想要一个每天重复的重复通知,但是我在创建时在主活动中编写的这段代码,但通知不会在第二天重复,只能工作一天。
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);
}
解决方案
推荐阅读
- javascript - react-native axios.get() [错误:请求失败,状态码 404]
- django - 如何在 Django 中为所有用户缓存视图
- javascript - 如何在 ReactJS 中为每个页面和内容创建条件渲染
- jquery - 更改 json 编码变量的值
- python - 为什么 Python 模块不能在命令行中工作?
- flutter - 在不使用 ThemeData 的情况下创建深色主题
- android - OnClick 侦听器在android中的布尔条件下无法正常工作
- javascript - Python-splash:使用 JS 下一步按钮抓取网站
- ejabberd - 向所有人发送 pidgine 消息
- angular - 带有旋钮的角度故事书(storybookjs/addons/knobs)带有select()的对象数组不起作用