Android TV-推荐(通知)不会自动取消

Android TV-推荐(通知)不会自动取消,android,android-5.0-lollipop,android-tv,Android,Android 5.0 Lollipop,Android Tv,在Android TV上用棒棒糖创建推荐(或通知)时,我无法让它自动取消 我正在使用Android TV开发者页面中推荐的“NotificationCompat.BigPictureStyle”。通知按设计工作,按预期触发PendingEvent,但不会自动取消并从建议栏中显示。第二次选择推荐会出现一个空白屏幕,因此我猜PendingEvent在这一点上是空的。(ADB在第二次调用时显示android.content.IntentSender$SendIntentException。) 在Nex

在Android TV上用棒棒糖创建推荐(或通知)时,我无法让它自动取消

我正在使用Android TV开发者页面中推荐的“NotificationCompat.BigPictureStyle”。通知按设计工作,按预期触发PendingEvent,但不会自动取消并从建议栏中显示。第二次选择推荐会出现一个空白屏幕,因此我猜PendingEvent在这一点上是空的。(ADB在第二次调用时显示android.content.IntentSender$SendIntentException。)

在Nexus播放器和Android电视模拟器上测试

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;


}

为了它的价值,我创造了一个解决这个问题的方法

我创建了一个新的活动,其唯一目的是从建议中获得一个待定的意图。 我更改了建议的原始挂起意图,以调用此新活动,而不是所需的活动。(所需的活动在我的应用程序之外。)在Extras中,我捆绑了我需要知道的关于我最初所需意图以及通知ID的所有信息。 当新活动启动时(在用户单击推荐后),我提取ID并取消推荐。然后,我提取所需意图的信息,创建意图,最后完成活动

public class TVRecommendationActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        Intent in = (Intent) getIntent();
        String jsonString = in.getStringExtra("jsonString");
        String fileUri = in.getStringExtra("fileUri");

        int id  =in.getIntExtra("notificationID", -1);

        NotificationManager nm = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        if (id >= 0 ) nm.cancel(id);

        JSONIntent newIntent = new JSONIntent(getApplicationContext());
        newIntent.setIncomingLocalFileURI(fileUri);
        Intent out = newIntent.buildIntentFromJSON(jsonString, fileUri);

        if (out != null) startActivity(out);
        finish();
    }

}

您希望它什么时候自动取消?当涉及到刷新、切换位置被取消/更新时,该建议由系统处理。我期望类似的自动取消行为发生在主流设备android通知上。例如,在Jellybean平板电脑上,当用户拉下通知栏并按下通知(auto cancel flag=true)时,PendingEvent被激活,通知从系统中消失。正如我所说,Android TV可能不是这样。这些建议是由系统处理的,所以是否应该删除你的内容并不是由你决定的。其他应用程序(如YouTube、DailyMotion、musixmatch等)也与此行为一致。也许你有道理,但为什么它会在第二次选择推荐时生成一个空白屏幕和一个异常?这听起来更像是你这边出了问题。我在构建公司的应用程序(musixmatch)时没有遇到过此问题。FWIW我也有同样的问题,但缺少
setAutoCancel()
,添加导致我的通知自动关闭。(Nexus播放器5.1.1 LMY47V)