【问题标题】:Why my notification does not work in android TV emulator?为什么我的通知在 android TV 模拟器中不起作用?
【发布时间】:2020-10-12 13:56:46
【问题描述】:

我正在尝试使用 android studio 和 TV 模拟器来实现一个 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

有什么想法吗?

【问题讨论】:

    标签: java android android-studio android-tv


    【解决方案1】:

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

    【讨论】:

    • 但我需要在电视屏幕上显示我的应用程序通知
    猜你喜欢
    • 2017-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多