意图开始导航活动

时间:2011-04-27 09:06:17

标签: android navigation android-intent

在我的应用程序中,我可以选择开始导航到选定的POI。基本上我想要的是从我的应用程序中启动一个转弯导航器。问题是我不知道安装了哪个(如果有的话)导航器。

所以,问题是如何通过显示一个合适的活动列表来启动一个意图,以便首先导航给用户,让他选择他想要使用哪一个?也很高兴找到一种方法将额外的参数传递给选定的活动(这听起来像是一个问题,因为不同的导航应用程序使用不同的名称作为他们的额外内容,我猜)。

如果不清楚:我正在寻找一种方法来显示一个适用于导航的应用程序列表,并选择使用一个默认值。

编辑:在这里找到实施http://datamoil.blogspot.com/2011/04/android-universal-intent-to-start.html

4 个答案:

答案 0 :(得分:21)

坏消息是,没有用于导航的标准Intent URI。

是的,存在google.navigation URI,应用可能会选择支持它。

我能想到的最佳解决方案是:

  • 明确检查已知应用
  • 隐式检查挂钩google.navigation的应用:或许 geo :(但之后你也会获得地图应用)

您可以使用PackageManage.queryIntentActivities

枚举可能的隐含目标

答案 1 :(得分:12)

尝试:

Intent intent = new Intent(Intent.ACTION_VIEW, 
    Uri.parse("google.navigation:q=New+York+NY")); 
startActivity(intent);

答案 2 :(得分:5)

首先,我在按钮的监听器中使用了onTap方法:

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("google.navigation:q=New+York+NY")); 
mContext.startActivity(i);

然后在清单中使用:

<activity android:name=".LaunchGPS" android:screenOrientation="portrait">
  <intent-filter>       
    <action android:name="android.intent.action.SEND" />
    <category android:name="android.intent.category.DEFAULT" />
  </intent-filter>
</activity>

这将打开您的手机拥有的任何导航器应用程序,例如VZ Navigagtor,Google或手机所加载的任何内容。第一次完美地为我工作。希望这能解决你的问题。

答案 3 :(得分:0)

我发现使用此代码有更多优势(仅用于显示可用的导航器应用程序)

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("geo:"));
if (intent.resolveActivity(getActivity().getPackageManager()) != null)   {
    startActivityForResult(Intent.createChooser(intent, "Continues with:", CHOOSE_NAVIGATOR_ID);
} else {
   // Handle failure...
}
相关问题