禁止谷歌地图意图选择对话框

时间:2023-04-24
本文介绍了禁止谷歌地图意图选择对话框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

当我使用这段代码时

   string url = "somegooglemapsurl.com";
   Intent mapLauncherIntent = new Intent(android.content.Intent.ACTION_VIEW,  Uri.parse(url));
   startActivity(mapLauncherIntent);

会弹出一个选择对话框,询问我是否要在地图应用程序或浏览器中打开此地图.我希望从我的应用程序活动到 Google 地图的过渡是无缝的.如何抑制此对话框并告诉 android 在地图活动中打开地图?

A selection dialog pops up asking if I want to open this map in the maps application or the browser. I'd like the transition from my application activity to Google Maps to be seamless. How can I suppress this dialog and tell android to open the map in the maps activity?

当我进入谷歌地图时,我想在某个位置使用公共蒸腾打开一个方向提示.我可以通过 google maps url 做到这一点,但是 url 会弹出选择对话框.

When I get into Google Maps I want to open a directions prompt using public transpiration in a certain location. I can do this through a google maps url, but a url brings up the selection dialog.

推荐答案

我还没有找到完美的解决方案,但这至少可以打开预先选择正确目的地和公共交通的地图.然后用户所要做的就是点击方向按钮.

I haven't found a perfect solution, but this will at least open maps with the correct destination and public transportation pre-selected. Then all the user has to do is hit the directions button.

它还会检查是否安装了谷歌地图,如果安装了,则更喜欢使用它.

It also checks if google maps is installed and prefers to use that if so.

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

 

// helper function to check if Maps is installed
private boolean isAppInstalled(String uri) {
    PackageManager pm = getApplicationContext().getPackageManager();
    boolean app_installed = false;
    try {
        pm.getPackageInfo(uri, PackageManager.GET_ACTIVITIES);
        app_installed = true;
    } catch (PackageManager.NameNotFoundException e) {
        app_installed = false;
    }
    return app_installed;
}

这篇关于禁止谷歌地图意图选择对话框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

上一篇:在 Android 中创建自定义对话框 下一篇:如何在对话框显示时隐藏键盘?

相关文章