0

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.

android_eng
  • 1,370
  • 3
  • 17
  • 40

1 Answers1

2

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);;
j2emanue
  • 60,549
  • 65
  • 286
  • 456
  • I was assuming that Reply is optional. What if I just want to show the notification and hear it but not reply. Mine is not a messaging application. – android_eng Dec 03 '15 at 18:25
  • only messaging and audio apps are allowed on the market at this time. Can you try adding the reply just to see if ti works, i think its mandatory because only messaging apps are allowed, thus a reply is required. Thats the info i got from google auto play review people when i tried to submit an app to the store that was not a messaging app a few weeks ago. – j2emanue Dec 03 '15 at 18:32