![](/img/trans.png)
[英]Java Android - Redmi 3 (MIUI) - Notification icons cannot be changed?
[英]Android notification importance cannot be changed
代碼摘要:
NotificationCompat.Builder notification;
NotificationManager manager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
...
int importance = NotificationManager.IMPORTANCE_HIGH;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, CHANNEL_TITLE, importance);
manager.createNotificationChannel(channel);
notification.setChannelId(CHANNEL_ID);
manager.notify(notificationId, 0, notification.build());
manager.getImportance()
總是返回 3(IMPORTANCE_DEFAULT)。 我怎樣才能改變重要性?
將頻道提交給 NotificationManager 后,您將無法更改重要性級別。 但是,用戶可以隨時更改他們對應用程序頻道的偏好。
https://developer.android.com/training/notify-user/channels
解決方案是引導用戶進行通知設置,並允許他修改您的頻道。 要在 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 設置中創建的所有頻道
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.