0

I am currently testing the wear 2.0 capabilities, and decided to go through the new maps implementation.

I tried to launch a quite basic navigation intent from the info window click of a marker, but the app keeps crashing with an unexpectedly weird error.

my code:

@Override
public void onMapReady(GoogleMap googleMap) {
    // Map is ready to be used.
    mMap = googleMap;

    // Set the long click listener as a way to exit the map.
    mMap.setOnMapLongClickListener(this);
    mMap.setOnInfoWindowClickListener(new GoogleMap.OnInfoWindowClickListener() {
        @Override
        public void onInfoWindowClick(Marker marker) {
            Uri gmmIntentUri = Uri.parse("google.navigation:q=" + marker.getPosition().latitude+","+marker.getPosition().longitude);
            Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
            startActivity(mapIntent);
        }
    });
    // Add a marker in Sydney, Australia and move the camera.
    LatLng sydney = new LatLng(-34, 151);
    mMap.addMarker(new MarkerOptions().position(sydney).title("Marker in Sydney"));
    mMap.moveCamera(CameraUpdateFactory.newLatLng(sydney));
}

the error i keep getting:

android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.VIEW dat=google.navigation:q=-34.0,151.0 }

Am i doing something wrong? running on a wear 2.0 android O emulator.

4

3 回答 3

2

我正在查看有关此的文档,并注意到一个不同之处。在 Google API 文档中,他们有一行明确设置了他们想要启动的应用程序的包。您的代码没有:

Uri gmmIntentUri = Uri.parse("google.navigation:q=Taronga+Zoo,+Sydney+Australia");
Intent mapIntent = new Intent(Intent.ACTION_VIEW, gmmIntentUri);
mapIntent.setPackage("com.google.android.apps.maps");
startActivity(mapIntent);

尝试从上面的代码片段中添加第三行,看看它是否启动了正确的应用程序。

于 2017-05-19T17:24:08.093 回答
0

ActivityNotFoundException当调用startActivity(Intent)或其变体之一失败时抛出,因为找不到 Activity 来执行给定的 Intent。你可以参考这个线程,它声明在创建你的 Android 虚拟设备时,你应该选择Google APIs作为你的目标。如果您没有安装它们,您可以使用 SDK Manager 下载它。

于 2017-05-19T15:16:29.230 回答
0

Wear 2.0 地图系统本身不包括导航,这就是它崩溃的原因。显然,它已被添加到即将推出的 Watch OS 中。

于 2018-05-10T06:18:16.030 回答