在 Android TV 上的 Lollipop 中创建推荐(或通知)时,我无法将其设置为自动取消。
我正在使用 Android TV 开发者页面中推荐的“NotificationCompat.BigPictureStyle”。通知按设计工作,按预期触发 PendingIntent,但不会自动取消并从推荐栏中消失。第二次选择推荐会出现一个空白屏幕,所以我猜当时 PendingIntent 为空。(ADB 在第二次调用时显示 android.content.IntentSender$SendIntentException。)
在 Nexus Player 和 Android TV 模拟器上测试。
private void buildAndroidTVRecommendation(String name, PendingIntent pIntent,
Context context2, Bundle extras) {
NotificationManager mNotificationManager = (NotificationManager)
context2.getSystemService(Context.NOTIFICATION_SERVICE);
Bitmap smallBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.air_share);
Notification notification = new NotificationCompat.BigPictureStyle(
( new NotificationCompat.Builder(context)
.setContentTitle("Air-Share - incoming share")
.setContentText("From: "+name)
.setContentInfo("Air-Share"))
.setGroup("Air-Share")
.setColor(0xFFFF2020)
.setCategory(Notification.CATEGORY_RECOMMENDATION)
.setLargeIcon(smallBitmap)
.setSmallIcon(R.drawable.air_share)
.setContentIntent(pIntent)
.setExtras(extras)
.setAutoCancel(true)
)
.build();
mNotificationManager.notify(pendingCounter, notification);
mNotificationManager = null;
}