【发布时间】:2016-04-17 20:50:20
【问题描述】:
我正在使用 Android TV 上的通知。不过,我无法在屏幕上收到通知。我正在使用 Android 6.0 上的 Nexus 播放器。
当我在手机上运行此代码时,会出现通知。但在电视上,通知不会出现。我错过了什么吗?
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
showNotification();
}
private void showNotification() {
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this)
.setSmallIcon(R.drawable.ic_launcher)
.setContentTitle("My notification")
.setContentText("Hello World!")
.setCategory(Notification.CATEGORY_RECOMMENDATION)
.setPriority(Notification.PRIORITY_HIGH) // heads up must be high priority
.setAutoCancel(true)
.setVibrate(new long[0]); // needed to guarantee heads up (need vibrate or ringtone)
Notification notification = new NotificationCompat.BigPictureStyle(mBuilder).build();
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
// mId allows you to update the notification later on.
int mId = 0;
mNotificationManager.notify(mId, notification);
}
编辑
我认为我的代码一直在工作。我的onCreate() 中有上述代码。所以,我期待在应用程序启动时会在屏幕上弹出某种通知。但是,我看到当我按下“主页”按钮时,该主页轮播中有一个推荐。当我单击它时,它正确地遵循了我的待定意图。如果我删除 .setCategory(Notification.CATEGORY_RECOMMENDATION) 行,这将不会发生。这就是 Android TV“通知”的关键
【问题讨论】:
标签: android android-notifications android-tv