要解决Android日程通知删除/取消不起作用的问题,可以尝试以下解决方法:
int notificationId = 1; // 假设通知ID为1
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.cancel(notificationId); // 删除指定ID的通知
// 创建通知渠道
String channelId = "my_channel_id";
CharSequence channelName = "My Channel";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(channelId, channelName, importance);
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.createNotificationChannel(channel);
// 创建并显示通知
int notificationId = 1;
NotificationCompat.Builder builder = new NotificationCompat.Builder(this, channelId)
.setSmallIcon(R.drawable.notification_icon)
.setContentTitle("My Notification")
.setContentText("Hello, World!");
notificationManager.notify(notificationId, builder.build());
// 删除指定ID的通知
notificationManager.cancel(notificationId);
// 通过Activity的上下文取消通知
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.cancel(notificationId);
// 通过Service的上下文取消通知
NotificationManager notificationManager = getSystemService(NotificationManager.class);
notificationManager.cancel(notificationId);
请根据你的具体情况选择适合的解决方法,并确保按照正确的方式删除/取消通知。