我尝试从我的应用程序调用导航.
我打电话给这个查询:
String link = "geo:" + posInfo.getLatitude() + "," + posInfo.getLongitude();Intent navigateIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(link));Intent chooser = Intent.createChooser(navigateIntent, ctx.getString(R.string.navigate_intent_chooser_Title));ctx.startActivity(chooser);
意图选择器显示2个应用程序:GoogleMaps和Waze.
使用Waze的导航工作完美,但使用谷歌地图它不起作用.我显示地图但没有导航说明.
如果我直接使用GoogleMaps,那么我可以导航,这与意图参数的传递方式有关.
我在其他一些答案中读到了我需要对谷歌地图使用另一个查询:
"Google.navigation:q.."
我有两个问题:
>我是否需要针对不同导航应用程序的不同查询?
>如果1为真,我如何使用不同查询的intentChooser?
解决方法:
这是我的解决方案:
private static final String PERFIX_DEFAulT_NAVIGATE_link_BY_COORDINATES = "geo:";private static final String PERFIX_DEFAulT_NAVIGATE_link_BY_ADDRESS = "geo:0,0?q=";private static final String PERFIX_DEFAulT_Google_NAVIGATE = "Google.navigation:q=";private static Intent getChooserNavigateIntent(Context context, Intent navigateIntent, POSEntityInfo posInfo, boolean isCoordinates) { // Check if there is a default app opener for this type of content. final PackageManager packageManager = context.getPackageManager(); ResolveInfo defaultAppInfo = packageManager.resolveActivity(navigateIntent, PackageManager.MATCH_DEFAulT_ONLY); // create the intent for intent chooser List<Intent> targetedOpenIntents = new ArrayList<Intent>(); List<ResolveInfo> appInfoList = packageManager.queryIntentActivitIEs(navigateIntent, PackageManager.MATCH_DEFAulT_ONLY); for (ResolveInfo appInfo : appInfoList) { String packagename = appInfo.activityInfo.packagename; Intent targetedOpenIntent = new Intent(androID.content.Intent.ACTION_VIEW).setPackage(packagename); targetedOpenIntent = getNavigateIntent(appInfo, targetedOpenIntent, isCoordinates, posInfo); targetedOpenIntents.add(targetedOpenIntent); } // create the intent chooser. delete the first member in the List(the default activity) Intent chooserIntent = Intent.createChooser(targetedOpenIntents.remove(0), context.getString(R.string.navigate_intent_chooser_Title)).putExtra(Intent.EXTRA_INITIAL_INTENTS, targetedOpenIntents.toArray(new Parcelable[]{})); return chooserIntent;}private static Intent getNavigateIntent(ResolveInfo appInfo, Intent navigateIntent, boolean isCoordinates, POSEntityInfo posInfo) { // link urls final String Google_NAVIGATE_PACKAGE = "com.Google.androID.apps.maps"; String suffixAddresslink = posInfo.getStreet() + " " + posInfo.getStreetNum() + "," + posInfo.getCity(); String suffixCoordinateslink = posInfo.getLatitude() + "," + posInfo.getLongitude(); boolean isGoogleMaps = Google_NAVIGATE_PACKAGE.equals(appInfo.activityInfo.packagename); //build the link url StringBuilder link = new StringBuilder(); link.append(isCoordinates ? (isGoogleMaps ? PERFIX_DEFAulT_Google_NAVIGATE : PERFIX_DEFAulT_NAVIGATE_link_BY_COORDINATES) : (isGoogleMaps ? PERFIX_DEFAulT_Google_NAVIGATE : PERFIX_DEFAulT_NAVIGATE_link_BY_ADDRESS)); link.append(isCoordinates ? suffixCoordinateslink : suffixAddresslink); Log.d(TAG, "link = " + link); return navigateIntent.setData(Uri.parse(link.toString()));}
//刚用>关闭标签
总结以上是内存溢出为你收集整理的android – 使用IntentChooser的导航应用程序 – 它是相同的查询?全部内容,希望文章能够帮你解决android – 使用IntentChooser的导航应用程序 – 它是相同的查询?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)