gpt4 book ai didi

Android Intent 选择器 - 导航应用

转载 作者:行者123 更新时间:2023-11-30 05:03:39 27 4
gpt4 key购买 nike

在我的应用程序中,我有一个按钮,可以打开带有已发送坐标的 Google map 。

 final ImageView view = findViewById(R.id.navigate);
view.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View view) {
Intent intent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("http://maps.google.com/maps?daddr="+gps1+","+gps2));
startActivity(intent);
}
});

这工作正常,但我想在点击按钮后向用户提供他设备中的所有导航应用程序。

所以不要自动打开 Google map ,而是让用户选择要使用的应用。

我找到了 this solution ,但这仅适用于 Google map 和 Waze。由于我不知道用户的设备上有哪些导航应用程序以及有多少导航应用程序,因此我无法对所有现有的导航应用程序进行硬编码。

String url = "waze://?ll=" + latitude + ", " + longitude + "&navigate=yes";
Intent intentWaze.setPackage("com.waze");
Intent intentWaze = new Intent(Intent.ACTION_VIEW, Uri.parse(url));

String uriGoogle = "google.navigation:q=" + latitude + "," + longitude;
Intent intentGoogleNav.setPackage("com.google.android.apps.maps");
Intent intentGoogleNav = new Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle));

String title = context.getString(R.string.title);
Intent chooserIntent = Intent.createChooser(intentGoogleNav, title);
Intent[] arr = new Intent[1];
arr[0] = intentWaze;
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr);
context.startActivity(chooserIntent);

那么有什么解决方案,可以提供用户拥有的所有导航应用吗?

例如共享功能是这样工作的:

 Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent.putExtra(Intent.EXTRA_TEXT,
infox);
sendIntent.setType("text/plain");
startActivity(Intent.createChooser(sendIntent, getString(R.string.share)));

这将显示许多具有共享可能性的应用程序。如何对带有 map 的应用执行同样的操作?

编辑:我将它添加到 google 和 waze 代码中,所以现在我在选择器中列出了:Google map 、Waze 和一个未知的 android 图标,当我点击它时,它会显示我设备上的所有导航应用程序!但是,只有当我单击那个未命名的图标时,它才会打开那些没有导航的 map 。

 String urlx = "geo:" + gps1 + ", " + gps2;
Intent intentOther = new Intent(Intent.ACTION_VIEW, Uri.parse(urlx));

我需要在点击按钮后立即显示所有这些应用。

最佳答案

这是一年后的事了,我实际上是在尝试使用上面的解决方案,但遇到了一些问题。比如选择器中的两个位智应用

我刚刚用 kotlin 重写了解决方案以及对我有用的东西

  val url = "waze://?ll=" + latitude + ", " + longitude + "&navigate=yes"
var intentWaze = Intent(Intent.ACTION_VIEW, Uri.parse(url)).setPackage("com.waze")

val uriGoogle = "google.navigation:q=" + latitude + "," + longitude
var intentGoogleNav = Intent(Intent.ACTION_VIEW, Uri.parse(uriGoogle)).setPackage("com.google.android.apps.maps")

val title: String = context.getString(R.string.app_name)
val chooserIntent = Intent.createChooser(intentGoogleNav, title)
val arr = arrayOfNulls<Intent>(1)
arr[0] = intentWaze
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, arr)
context.startActivity(chooserIntent)

关于Android Intent 选择器 - 导航应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57774155/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com