如何在Android TV 8.0 Mi Box中添加通知

时间:2019-07-18 06:50:35

标签: android notifications android-tv

我正在尝试向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());

但是它没有被添加到主屏幕的通知选项卡中。 相同的代码在Amazon fireTv enter image description here

中工作正常

0 个答案:

没有答案