Java 无法更改Android通知的重要性

Java 无法更改Android通知的重要性,java,android,Java,Android,代码摘要: NotificationCompat.Builder通知; NotificationManager=(NotificationManager)context.getSystemService(context.NOTIFICATION\u服务); ... int重要性=NotificationManager.importance\u HIGH; NotificationChannel=新的NotificationChannel(频道ID、频道标题、重要性); manager.creat

代码摘要:

NotificationCompat.Builder通知;
NotificationManager=(NotificationManager)context.getSystemService(context.NOTIFICATION\u服务);
...
int重要性=NotificationManager.importance\u HIGH;
NotificationChannel=新的NotificationChannel(频道ID、频道标题、重要性);
manager.createNotificationChannel(频道);
通知.setChannelId(通道ID);
manager.notify(notificationId,0,notification.build());
manager.getImportance()
始终返回3(默认值为重要性)。 我如何改变重要性

一旦您将频道提交给NotificationManager,您就不能 更改重要性级别但是,用户可以更改其 随时选择应用程序频道的首选项。

解决方案是引导用户进行通知设置,并允许用户修改您的频道。要在android设置中打开频道,有一个意图:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
      final Intent intent = new Intent(Settings.ACTION_CHANNEL_NOTIFICATION_SETTINGS);
      intent.putExtra(Settings.EXTRA_APP_PACKAGE, getActivity().getPackageName());
      intent.putExtra(Settings.EXTRA_CHANNEL_ID, channelID);
      if (intent.resolveActivity(getActivity().getPackageManager()) != null) {
          startActivity(intent);
      } else {
          Toast.makeText(getActivity(), R.string.not_found, Toast.LENGTH_LONG).show();
      }
}

另一个解决方案是创建一个新频道并使用该频道,但用户始终可以看到您在Android设置中创建的所有频道。另一个解决方案是创建一个新频道并使用该频道,但用户始终可以看到您在Android设置中创建的所有频道