无法从 Wear 2.0 设备启动导航意图

Unable to launch navigation intent from Wear 2.0 device

我目前正在测试 wear 2.0 功能,并决定通过新地图实施。

我试图通过点击标记 window 信息启动一个非常基本的导航意图,但应用程序不断崩溃并出现意外的奇怪错误。

我的代码:

@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));
}

我不断收到的错误:

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

我是不是做错了什么? 运行 on a wear 2.0 android O emulator.

ActivityNotFoundException is thrown when a call to startActivity(Intent) or one of its variants fails because an Activity can not be found to execute the given Intent. You may refer with this thread which stated that when creating your Android Virtual Device, you should select Google APIs 作为您的目标。如果没有安装,可以使用SDK Manager下载。

我正在浏览 documentation 并注意到一个不同之处。在 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);

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

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