Уведомление не отображается с помощью Android Auto

Я следовал учебному пособию по 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());

Я не мог понять, где я иду не так, как это довольно новое.

1 ответ

Решение

Вы не устанавливаете действие ответа, чтобы Android Auto не показывал уведомление. Сначала создайте удаленный вход, как это в самом начале:

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

затем установите ответное действие в конструкторе unreadConversation. Так что теперь ваш будет выглядеть так:

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