【问题标题】:android - coordinates intent to launch other appsandroid - 协调启动其他应用程序的意图
【发布时间】:2023-12-27 16:24:01
【问题描述】:

我想从我的应用分享坐标,我想让我的用户选择另一个 gps 应用并启动它们。 我有这个代码,但它只打开谷歌地图,我想让我的用户能够选择一个应用程序

    Intent intent = new Intent(android.content.Intent.ACTION_VIEW, 
    Uri.parse("http://maps.google.com/maps?saddr=20.344,34.34&daddr=20.5666,45.345"));
startActivity(intent);

我该怎么做?

【问题讨论】:

标签: android android-gps


【解决方案1】:

如果您想要一个选择器,它将向用户提供其设备中所有带有地图的应用程序,请尝试以下解决方案:

  1. 在清单中添加 data android:scheme="geo",但将意图过滤器分为 2 部分,如下所示:

代码:

<intent-filter>
                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
     <intent-filter>
      <action android:name="android.intent.action.VIEW" />
                    <data android:scheme="geo" />
     </intent-filter>

之后,您可以使用地理链接。

  1. 在按钮点击或任何地方创建意图:

     Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));```
    

这应该向用户提供他已安装的所有地图应用程序(Google、Waze、Locus 等)。它还显示地图上的坐标,Waze 也会自动计算路线。

如果用户没有任何地图应用程序,您还应该注意这种情况,创建一些异常。

【讨论】:

    最近更新 更多