问题
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:
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.
回答1:
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();
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);;
来源:https://stackoverflow.com/questions/34053761/notification-not-showing-up-using-android-auto