【发布时间】: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