问题描述
我想启用所有通知选项,但我不能这样做(请参阅 sreenshot)。 我安装了电报,默认情况下它的所有选项都是启用的。 为什么以及如何?
目前我有这个代码:
NotificationManager notifManager=(NotificationManager)getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
NotificationChannel mChannel = new NotificationChannel(NOTIFICATION_CHANNEL_ID, "My Notifications", NotificationManager.IMPORTANCE_HIGH);
// Configure the notification channel.
mChannel.setDescription("Common notifications");
mChannel.enableLights(true);
mChannel.setLightColor(Color.RED);
mChannel.setVibrationPattern(new long[]{0, 1000, 500, 1000});
mChannel.setLockscreenVisibility(Notification.VISIBILITY_PUBLIC);
mChannel.enableVibration(true);
notifManager.createNotificationChannel(mChannel);
}
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(getApplicationContext(), NOTIFICATION_CHANNEL_ID)
.setDefaults(Notification.DEFAULT_SOUND | Notification.DEFAULT_VIBRATE)
.setPriority(NotificationCompat.PRIORITY_HIGH)
.setWhen(System.currentTimeMillis())
.setSmallIcon(icon)
.setColor(color)
.setTicker("")
.setContentTitle("Title")
.setContentText("ContextText")
.setContentInfo("Info")
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setAutoCancel(true);
NotificationManager mNotificationManager =
(NotificationManager) getApplicationContext().getSystemService(Context.NOTIFICATION_SERVICE);
mNotificationManager.notify(SOMEID, mBuilder.build());
1楼
我将此权限添加到 Android 清单文件中。 它对我有用。
<uses-permission android:name="android.permission.ACCESS_NOTIFICATION_POLICY" />