3

Our app is going to support Android Auto. We have a navigation button on car screen. When user press that button, we want to open Google Map directly for navigation (on car screen, not on app).

Here's my code:

val uri = Uri.parse("geo:0,0?q=${latitude},${longitude}(${name})")
val intent = Intent(CarContext.ACTION_NAVIGATE, uri)
intent.setPackage("com.google.android.apps.maps")
carContext.startCarApp(intent)

This is the part of "manifest" for Android auto.

// android auto

        <meta-data
                android:name="com.google.android.gms.car.application"
                android:resource="@xml/automotive_app_desc"/>
        <meta-data
                android:name="androidx.car.app.minCarApiLevel"
                android:value="1"/>

        <service
                android:name=".programameudisservice"
                android:exported="true">
            <intent-filter>
                <action android:name="androidx.car.app.CarAppService" />
                <category android:name="androidx.car.app.category.NAVIGATION"/>

            </intent-filter>

        </service>
        // android auto

Now when I have other app can handle this intent, such as the navigation app or showcase app of android auto sample project, it will start navigation with other apps sometimes.

Does anyone know how to explicitly open Google Map for navigation on car screen?

oscarabilleira
  • 121
  • 1
  • 12
Kuan Hsien
  • 31
  • 2

2 Answers2

0

Please see the documentation here https://cs.android.com/androidx/platform/frameworks/support/+/androidx-main:car/app/app/src/main/java/androidx/car/app/CarContext.java;l=324?q=f:CarContext

Android Auto will use the user's chosen nav app, we disallow setting the package name.

0

You could create your intent like this instead (note the URI difference):

val uri = Uri.parse("google.navigation:q=${latitude},${longitude}")
val intent = Intent(Intent.ACTION_VIEW, uri)
narko
  • 3,645
  • 1
  • 28
  • 33