没有显示使用Android Auto的通知 [英] Notification not showing up using Android Auto

本文介绍了没有显示使用Android Auto的通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遵循Udacity的教程和Android汽车的开发者网站。我正在使用DVU进行测试。通知没有显示在DHU上,但在手机上显示是我的代码:

I followed the tutorial on Udacity and the developer site for Android auto. I am using a DVU for testing. The notifications don't show up on the DHU but appears on the phone here is my code:

使用GcmListenerService:

Using GcmListenerService:

 final PendingIntent contentIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT
                | PendingIntent.FLAG_ONE_SHOT);

final PendingIntent contentIntent = stackBuilder.getPendingIntent(0, PendingIntent.FLAG_UPDATE_CURRENT
                | PendingIntent.FLAG_ONE_SHOT);
        Intent msgHeardIntent = new Intent()
                .addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES)
                .setAction("com.xyz.abc.MY_ACTION_MESSAGE_HEARD")
                .putExtra("conversation_id", 9999);
        PendingIntent msgHeardPendingIntent =
                PendingIntent.getBroadcast(getApplicationContext(),
                        9999,
                        msgHeardIntent,
                        PendingIntent.FLAG_UPDATE_CURRENT);

        NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
                new  NotificationCompat.CarExtender.UnreadConversation.Builder("TestAndroidAuto")
                        .setReadPendingIntent(msgHeardPendingIntent);

        unreadConvBuilder.addMessage(description);
        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
                        .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
                        .setSmallIcon(R.drawable.ic_stat_notification_icon)
                        .setContentTitle(title)
                        .setTicker(ticker)
                        .setStyle(new NotificationCompat.BigTextStyle()
                                .bigText(description))
                        .setContentText(description)
                        .setDefaults(Notification.DEFAULT_ALL);
        mBuilder.extend(new NotificationCompat.CarExtender().setUnreadConversation(unreadConvBuilder.build()));
        mBuilder.setContentIntent(contentIntent);
        mBuilder.setAutoCancel(true);
        mNotificationManager = NotificationManagerCompat.from(getApplicationContext());
        mNotificationManager.notify(REMOTE_NOTIFICATION_ID, mBuilder.build());

我无法理解我错在哪里,因为这是相当新的。

I could not understand where I am going wrong as this is fairly new.

推荐答案

你没有设置回复动作,所以android auto不会显示通知。首先在开始时创建一个如下所示的远程输入:

Your not setting the reply action so android auto would not show the notification. First create a remote input like this at the very beginning:

// Build a RemoteInput for receiving voice input in a Car Notification
        RemoteInput remoteInput = new RemoteInput.Builder(9999)
                .setLabel(msg)
                .build();

然后在unreadConversation构建器中设置replyAction。所以现在你的样子如下所示:

then set the replyAction in the unreadConversation builder. So now yours will look like this:

NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
            new  NotificationCompat.CarExtender.UnreadConversation.Builder("TestAndroidAuto")
                    .setReadPendingIntent(msgHeardPendingIntent)
            .setReplyAction(msgHeardPendingIntent, remoteInput);;

这篇关于没有显示使用Android Auto的通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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