Can I programmatically launch navigation on Android Wear?

I am making an extension for my android app. I can get android wear notifications no problem with all the data I want. I have a lat and a long for each POI for which im sending a notification and I want to add a "Navigate to" function inside the android wear notification that will take these coordinates and google navigation on the smart watch. Is it possible? Can you provide an example or documentation. Thanks to

This is the sample code I am using in my app to run google maps on my phone by clicking the "Open on map" button on my android wear.

    Intent mapIntent = new Intent(Intent.ACTION_VIEW);
    Uri geoUri = Uri.parse("geo:0,0?q=" + chapter.getLatitude() + "," + chapter.getLongitude());
    mapIntent.setData(geoUri);
    PendingIntent mapPendingIntent =
            PendingIntent.getActivity(context, 0, mapIntent, 0);
    ...

    .addAction(R.drawable.ic_map_white_24dp, "Open on map", mapPendingIntent)

      

+3


source to share


1 answer


As far as I understand, what you are trying to do, you have already achieved your goal. Once you can start navigating on your phone, it will automatically appear on your watch as a notification card that appears at the bottom of your time zone.

I am currently developing an application in which I am doing the same, except I am using CardFragments to trigger an activity instead of using Wearable Notifications and PendingIntents. When I click the action button on the CardFragment displayed on my watch, I send a Wearable Message to my phone app, which runs the following code when it receives that particular message.



String uri = "google.navigation:q=" + String.valueOf(latitude) + "," + String.valueOf(longitude);
Intent mapsIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
mapsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(mapsIntent);

      

I need to set FLAG_ACTIVITY_NEW_TASK because this code is part of a normal java class method. Everything works fine when the phone screen is unlocked and the screen is on. However, navigation should also be started when the phone is locked. Here I am fighting now.

+1


source







All Articles