简体   繁体   中英

How to send a google map notification for android auto simulator?

I'm developing an app for Android Auto . I wanted to send a map notification like this(I'm not implmented yet the big view) 下图。

I tried it with the following code. But it's failed to send a map navigation notification.

private void sendNotificationForConversation(Conversation conversation) {
    // A pending Intent for reads
    double latitude = 31.249351;
    double longitude = 121.45905;
    Intent notificationIntent = new Intent(Intent.ACTION_VIEW, Uri
            .parse("http://maps.google.com/maps?saddr="
                    + latitude + ","
                    + longitude + "&daddr="
                    + 31.186371 + "," + 121.489885));

    notificationManager = (NotificationManager) getApplicationContext()
            .getSystemService(Context.NOTIFICATION_SERVICE);
    Notification notification = new Notification(R.drawable.notification_icon, "Kohls store ahead", 1000);
    RemoteViews contentView = new RemoteViews(getPackageName(), R.layout.activity_kcc);
    contentView.setTextViewText(R.id.hello, "This is the KCC layout");
    notification.contentView = contentView;

    PendingIntent readPendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);

    notification.contentIntent = readPendingIntent;

    notification.flags |= Notification.FLAG_AUTO_CANCEL; // clear the notification
    notification.defaults |= Notification.DEFAULT_LIGHTS; // LED
    notification.defaults |= Notification.DEFAULT_VIBRATE; //Vibration
    notification.defaults |= Notification.DEFAULT_SOUND; // Sound

    // Build a RemoteInput for receiving voice input in a Car Notification
    RemoteInput remoteInput = new RemoteInput.Builder(EXTRA_VOICE_REPLY)
            .setLabel(getApplicationContext().getString(R.string.notification_reply))
            .build();

    // Building a Pending Intent for the reply action to trigger
    PendingIntent replyIntent = PendingIntent.getBroadcast(getApplicationContext(),
            conversation.getConversationId(),
            getMessageReplyIntent(conversation.getConversationId()),
            PendingIntent.FLAG_UPDATE_CURRENT);

    // Create the UnreadConversation and populate it with the participant name,
    // read and reply intents.
    NotificationCompat.CarExtender.UnreadConversation.Builder unreadConvBuilder =
            new NotificationCompat.CarExtender.UnreadConversation.Builder(conversation.getParticipantName())
                    .setLatestTimestamp(conversation.getTimestamp())
                    .setReadPendingIntent(readPendingIntent)
                    .setReplyAction(replyIntent, remoteInput);


    NotificationCompat.Builder builder = new NotificationCompat.Builder(getApplicationContext())
            .setContent(contentView)
            .setContentIntent(readPendingIntent)
            .extend(new NotificationCompat.CarExtender()
                    .setUnreadConversation(unreadConvBuilder.build()));


    MessageLogger.logMessage(getApplicationContext(), "Sending notification "
            + conversation.getConversationId() + " conversation: " + conversation);

    notificationManager.notify(conversation.getConversationId(), builder.build());
}

with this I got an empty notification on simulator and there's nothing visible on status bar. I want to show a navigating map on android auto car device after click on this notification. How may I fix this?

Thanks in Advance!

I think you just can not do it now; There is no way you can launch the Android Auto's Google Maps activity directly. I tried to launch the Direction intent by:

    Uri gmmIntentUri = Uri.parse("google.navigation:q=San+Francisco");
    Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
    mapIntent.setPackage("com.google.android.apps.maps");
    mapIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    context.startActivity(mapIntent);

but it does not seem to work.. I don't have the real head unit so I am not sure if this would work on the real device, but this is my best guess.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM