我正在尝试向android电视中的设置通知菜单添加通知。 使用以下代码
String CHANNEL_ID = "test";
NotificationManager notificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
// Create the NotificationChannel, but only on API 26+ because
// the NotificationChannel class is new and not in the support library
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
CharSequence name = "test";
String description = "descriptiom";
int importance = NotificationManager.IMPORTANCE_DEFAULT;
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
channel.setDescription(description);
// Register the channel with the system; you can't change the importance
// or other notification behaviors after this
notificationManager.createNotificationChannel(channel);
}
int notificationId=22;
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context, CHANNEL_ID)
.setSmallIcon(R.drawable.nagra_logo)
.setContentTitle("tite")
.setContentText("content")
.setAutoCancel(true);
notificationManager.notify(notificationId, mBuilder.build());
中工作正常