Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/grails/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 抑制谷歌地图意向选择对话框_Android_Dialog_Maps - Fatal编程技术网

Android 抑制谷歌地图意向选择对话框

Android 抑制谷歌地图意向选择对话框,android,dialog,maps,Android,Dialog,Maps,当我使用这个代码时 string url = "somegooglemapsurl.com"; Intent mapLauncherIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url)); startActivity(mapLauncherIntent); 弹出一个选择对话框,询问我是否要在“地图”应用程序或浏览器中打开此地图。我希望从我的应用程序活动到谷歌地图的过渡是无缝的。如何抑制此

当我使用这个代码时

   string url = "somegooglemapsurl.com";
   Intent mapLauncherIntent = new Intent(android.content.Intent.ACTION_VIEW,  Uri.parse(url));
   startActivity(mapLauncherIntent);
弹出一个选择对话框,询问我是否要在“地图”应用程序或浏览器中打开此地图。我希望从我的应用程序活动到谷歌地图的过渡是无缝的。如何抑制此对话框并告诉android在“地图”活动中打开地图


编辑:当我进入谷歌地图,我想打开一个方向提示使用公共蒸腾在某个位置。我可以通过谷歌地图url来实现这一点,但是url会打开选择对话框。

首先,我要指出的是,摆脱选择对话框不一定是一件好事。你想让用户在处理数据的方式上有尽可能多的选择,这是安卓生态系统之美的一部分。也就是说,在不理解你的申请的情况下做出判断是不公平的,所以

您可以使用
geo
协议:

而不是像这样传递
maps.google.com/blabla
格式化您的URI
geo:0,0?q=my+street+address

例如:

Intent mapLauncherIntent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("geo:0,0?q=1111+imaginary+dr"));

以下是我目前发现的不同方法:

1。直接启动导航:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=my+street+address");
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
这一明确意图将直接启动谷歌导航:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=my+street+address");
startActivity(intent);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps/?daddr=my+street+address");
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
这将直接启动导航(不幸的是,用户无法选择交通方式)

2。让用户选择运输方式:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=my+street+address");
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
这将启动Google导航应用程序,但允许用户在开始导航前选择交通方式:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("google.navigation:q=my+street+address");
startActivity(intent);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps/?daddr=my+street+address");
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);

3。从谷歌地图开始:

Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("geo:0,0?q=my+street+address");
intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
startActivity(intent);
这将启动地图,用户可以从中启动导航(并选择运输模式)

在所有情况下,您都应该使用PackageManager和QueryInputActivities()或异常处理来处理用户未安装Google地图/导航的情况

在我的应用程序中,我使用方法2,效果很好。希望这有帮助

加载项:这里有一个方法来检查是否安装了应用程序。在调用intent.setClassName()之前,我使用它检查是否安装了“com.google.android.apps.maps”


我还没有找到一个完美的解决方案,但这至少会打开带有正确目的地和预先选择的公共交通的地图。然后用户只需点击方向按钮

它还检查是否安装了谷歌地图,如果安装了,它更愿意使用谷歌地图

Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse("http://maps.google.com/maps?daddr=0,0%20(Imaginary%20Place)&dirflg=r"));
if (isAppInstalled("com.google.android.apps.maps")) {
    intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
}
startActivity(intent);


我看了一下,但我需要只使用公共交通来加载谷歌地图的方向。我知道你可以通过谷歌地图的url来做到这一点,但你可以通过地理位置来做到吗?完整的规范在这里:我不确定,但我怀疑。我有另一个想法要研究。对不起,我现在没有更多的时间来研究。我相信,如果你知道“地图”活动的名称,你可以使用以下命令启动它:,java.lang.String)
com.google.android.maps
是程序包名称,但我不确定活动名称。然后,问题是如何添加正确的附加项。不知道怎么做。我希望已经为用户选择了合适的交通方式。只需一个便条-强制街道查看需要
com.google.android.Street
软件包和
com.google.android.Street
活动;意图如中所述