使用Intent.createChooser使用Waze和Google Maps导航显示两次Waze图标 [英] Navigation with Waze and Google Maps using Intent.createChooser shows Waze icon twice

查看:156
本文介绍了使用Intent.createChooser使用Waze和Google Maps导航显示两次Waze图标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在找到答案后创建了这个问题,我不确定礼节,但是它

I'm creating this question after finding the answer, I was not sure about the etiquette, but it seems to be OK (plus, I see now there's a built-in option).

问题如标题中所述,我们使用类似于以下代码的方式创建了一个意图选择器:

The problem was as described in the title, we created an intent chooser using code that resembles this:

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

String uriGoogle = "google.navigation:q=" + latitude + "," + longitude;
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);

并获得了两个Waze图标和一个Google Maps图标;更糟糕的是,位智图标之一无法启动导航(仅打开应用程序).

And got two Waze icons and one Google Maps icon; and worse, one of the Waze icons did not start the navigation (only open the app).

我们不能使用geo: intent,因为我们需要控制显示的intent(我们不想一直显示两个intent)和Google Maps中的导航类型(例如:&mode=w).

推荐答案

一段时间后,我使用了在此处找到的解决方案 ,并且只有一个图标可以正常工作.正如我在问题中所写的那样,我无法使用此解决方案,因为它缺乏所需的灵活性,因此在查看代码后,我发现缺少的是:

After some time I used the solution found here, and there was only one icon that was working properly. As I wrote in the question, I could not use this solution because it lacks the flexibility I needed, so after looking at the code I saw that what was missing was this:

intentWaze.setPackage("com.waze");
// and more importantly, this:
intentGoogleNav.setPackage("com.google.android.apps.maps");

Waze似乎正在听Google Maps意图(并且不能很好地使用它),这就是为什么有两个图标的原因.

It seems that Waze is listening to the Google Maps intent (and does not work well with it), and that's why there were two icons.

这篇关于使用Intent.createChooser使用Waze和Google Maps导航显示两次Waze图标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆