我按照Udacity上的教程和Android auto的开发者网站进行了操作。我正在使用DVU进行测试。通知不会显示在DHU上,但在手机上显示的是我的代码:
使用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());
我无法理解我哪里出错了,因为这是相当新的。
答案 0 :(得分:2)
您没有设置回复操作,因此android auto不会显示通知。首先在一开始就创建一个这样的远程输入:
// Build a RemoteInput for receiving voice input in a Car Notification
RemoteInput remoteInput = new RemoteInput.Builder(9999)
.setLabel(msg)
.build();
然后在unreadConversation构建器中设置replyAction。所以现在你的看起来像这样:
NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
new NotificationCompat.CarExtender.UnreadConversation.Builder("TestAndroidAuto")
.setReadPendingIntent(msgHeardPendingIntent)
.setReplyAction(msgHeardPendingIntent, remoteInput);;