为什么我的通知在android TV模拟器中不起作用?

问题描述

我正在尝试通过使用android studio和电视模拟器来实现android TV应用程序。

我在主要活动的onCreate函数调用以下代码块。它可以在android移动设备上运行,但不能在Android TV模拟器上运行。

String channel_name = "myChannel";
String channel_description = "mySChannel";
String CHANNEL_ID = "idididf";
NotificationCompat.Builder builder = new NotificationCompat.Builder(this,CHANNEL_ID)
        .setSmallIcon(R.drawable.ic_my_icon)
        .setContentTitle("My notification")
        .setContentText("Much longer text that cannot fit one line...")
        .setStyle(new NotificationCompat.BigTextStyle()
                .bigText("Much longer text that cannot fit one line..."))
        .setPriority(NotificationCompat.PRIORITY_DEFAULT);
notificationmanager notificationmanager = getSystemService(notificationmanager.class);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    CharSequence name = channel_name;
    String description = channel_description;
    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);
}

notificationmanager.notify(12312,builder.build()); // 0 is the request code,it should be unique id

有什么主意吗?

解决方法

除极少数例外,通知不会在Android TV上显示。