我编写了以下方法来发送通知,通知正在工作,但是当按下通知操作按钮时settings
,未打开通道设置的待处理意图。任何想法为什么这不起作用?
private static final String NOTIFICATION_GROUP_ID = "notification_group";
private static final int NOTIFICATION_ID = 546893;
private static final String NOTIFICATION_CHANNEL_ID = "notification_channel";
public static void sendNotification(Context context, int iconId, String title, String message, String channelId, int notificationId)
{
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
NotificationChannel notificationChannel = new NotificationChannel(
channelId, title, NotificationManager.IMPORTANCE_HIGH);
notificationManager.createNotificationChannel(notificationChannel);
Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
intent.putExtra(Settings.EXTRA_APP_PACKAGE, context.getPackageName());
intent.putExtra(Settings.EXTRA_CHANNEL_ID, NOTIFICATION_ID);
PendingIntent settingsIntent = PendingIntent.getActivity(context, 0, intent, 0);
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(context, channelId)
.setColor(ContextCompat.getColor(context, R.color.colorPrimary))
.setSmallIcon(iconId)
.setContentTitle(title)
.setContentText(message)
.setStyle(new NotificationCompat.BigTextStyle().bigText(message))
.setGroup(NOTIFICATION_GROUP_ID)
.addAction(iconId, "settings", settingsIntent)
.setAutoCancel(true);
notificationManager.notify(NOTIFICATION_ID, notificationBuilder.build());
}