通知不会出现在Android TV上 [英] Notification Won't Appear on Android TV

查看:147
本文介绍了通知不会出现在Android TV上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在Android TV上播放通知.但是,我还没有收到显示在屏幕上的通知.我正在使用Android 6.0上的Nexus播放器.

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);
}

编辑 我认为我的代码一直都在工作.我的onCreate()中有上面的代码.因此,我期望在应用启动时在屏幕上弹出某种通知.但是,我看到当我按下主页"按钮时,该主页轮播中有一个推荐.当我单击它时,它正确地遵循了我的待定意图.如果删除.setCategory(Notification.CATEGORY_RECOMMENDATION)行,则不会发生这种情况.这就是Android TV通知"的关键

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"

推荐答案

电视通知在某些方面与电话通知有所不同,并且可能具有特定的附加参数.尝试添加更多属性.这是我在其中一个有效的应用中实现的电视通知的摘要.

A TV notification is going to be different in some ways from a phone notification and may have specific additional parameters. Try adding a few more attributes. Here's a snippet of a TV notification I have implemented in one of my apps which works.

Notification notification = new NotificationCompat.BigPictureStyle(
            new NotificationCompat.Builder(mContext)
                    .setContentTitle(video.getString("title"))
                    .setContentText(mDescription)
                    .setPriority(mPriority)
                    .setLocalOnly(true)
                    .setOngoing(true)
                    .setColor(mContext.getResources().getColor(android.R.color.holo_green_dark))
                    .setCategory(Notification.CATEGORY_RECOMMENDATION)
                    .setLargeIcon(thumbnail)
                    .setSmallIcon(R.drawable.ic_note)
                    .setContentIntent(launchApp(mContext))
                    .setExtras(null))
            .build();


    return notification;

这篇关于通知不会出现在Android TV上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆