首页 > 解决方案 > 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);
            }

标签: javaandroid

解决方案


推荐阅读