I am playing with notifications on Android TV. I have not been able to get a notification to appear on the screen though. I am using the Nexus player which is on Android 6.0.
When I run this code on my phone, the notification appears. But on TV, the notification does not appear. Am I missing something?
@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);
}
EDIT
I think my code was working all along. I had the above code in my onCreate()
. So, I was expecting to see some sort of notification pop up on screen when the app launched. However, I see that when I press the "home" button that there is a Recommendation in that home Carousel. When I click it, it correctly follows my pending intent. This won't happen if I remove the .setCategory(Notification.CATEGORY_RECOMMENDATION)
line. So that is the key for Android TV "notifications"