Android 启动Google Maps时,未找到可处理意图的活动

Android 启动Google Maps时,未找到可处理意图的活动,android,android-intent,Android,Android Intent,这很好,可以启动Google Play Music(尽管奇怪的是,它让我可以选择“Play Music”或“Google Play Music”): 同样的事情对于谷歌地图也不起作用。这: Intent mapIntent = new Intent(Intent.ACTION_MAIN); mapIntent.setPackage("com.google.android.apps.maps"); mapIntent.addF

这很好,可以启动Google Play Music(尽管奇怪的是,它让我可以选择“Play Music”或“Google Play Music”):

同样的事情对于谷歌地图也不起作用。这:

            Intent mapIntent = new Intent(Intent.ACTION_MAIN);
            mapIntent.setPackage("com.google.android.apps.maps");
            mapIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(mapIntent);
给出:

Unhandled exception in callback
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.intent.action.MAIN flg=0x10000000 pkg=com.google.android.apps.maps }
    at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1805)
    at android.app.Instrumentation.execStartActivity(Instrumentation.java:1514)
    at android.app.ContextImpl.startActivity(ContextImpl.java:663)
    at android.app.ContextImpl.startActivity(ContextImpl.java:645)
    at android.content.ContextWrapper.startActivity(ContextWrapper.java:331)

我仔细检查了包裹的名称。我只能猜那不是我应该用的绳子。我做错了什么?

地图不一样

根据谷歌地图文档,他们说

所有谷歌地图的意图都称为视图-操作-操作视图

请尝试以下方法:

showMap(Uri.parse("geo:47.6,-122.3"););

public void showMap(Uri geoLocation) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geoLocation);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    } else{
        // No application is available that can handle this intent
    }
}
请检查以下文件:


此外,图中的意图请求部分与地图不一致

根据谷歌地图文档,他们说

所有谷歌地图的意图都称为视图-操作-操作视图

请尝试以下方法:

showMap(Uri.parse("geo:47.6,-122.3"););

public void showMap(Uri geoLocation) {
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setData(geoLocation);
    if (intent.resolveActivity(getPackageManager()) != null) {
        startActivity(intent);
    } else{
        // No application is available that can handle this intent
    }
}
请检查以下文件:

另外,在中的“意图请求”部分

奇怪的是,它让我可以选择“播放音乐”或“谷歌播放音乐”

一个应用程序可以有多个
ACTION\u MAIN
活动。例如,它可能有多个launcher活动,或者可能有一个专门的launcher活动供Android TV与标准launcher活动配合使用

我做错了什么

你的意思是,除了假设用户安装了谷歌地图,启用了谷歌地图,并且想要使用谷歌地图,而不是使用其他一些地图应用程序之外

您正在
com.google.android.apps.maps
中查找
ACTION\u MAIN
CATEGORY\u DEFAULT
。对于
类别\默认值
,任何应用程序都不要求有
ACTION\u MAIN

通过创建一个
意图
,不将其与任何类别关联,并将其与
startActivity()
一起使用,可以暗示您选择了
CATEGORY\u DEFAULT
。您可能希望使用
CATEGORY\u启动器
。或

奇怪的是,它让我可以选择“播放音乐”或“谷歌播放音乐”

一个应用程序可以有多个
ACTION\u MAIN
活动。例如,它可能有多个launcher活动,或者可能有一个专门的launcher活动供Android TV与标准launcher活动配合使用

我做错了什么

你的意思是,除了假设用户安装了谷歌地图,启用了谷歌地图,并且想要使用谷歌地图,而不是使用其他一些地图应用程序之外

您正在
com.google.android.apps.maps
中查找
ACTION\u MAIN
CATEGORY\u DEFAULT
。对于
类别\默认值
,任何应用程序都不要求有
ACTION\u MAIN


通过创建一个
意图
,不将其与任何类别关联,并将其与
startActivity()
一起使用,可以暗示您选择了
CATEGORY\u DEFAULT
。您可能希望使用
CATEGORY\u启动器
。或者,.

使用
操作视图更改
操作主视图

Intent mapIntent = new Intent(Intent.ACTION_VIEW);
mapIntent.setPackage("com.google.android.apps.maps");
mapIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mapIntent);

使用
ACTION\u视图更改
ACTION\u MAIN

Intent mapIntent = new Intent(Intent.ACTION_VIEW);
mapIntent.setPackage("com.google.android.apps.maps");
mapIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(mapIntent);

谷歌地图安装在那个设备上了吗?谷歌地图安装在那个设备上了吗?啊,我明白了。是的,显然我还没有完成我的应用程序的开发-我不认为我说过这是生产代码。啊,我明白了。是的,显然我还没有完成我的应用程序的开发——我想我并没有说这是生产代码。