Waze Deep Links

时间:2017-11-17 19:44:28

标签: c# android xamarin xamarin.android waze

我正在使用Xamarin Forms(跨平台)开发应用程序,我正试图从我的应用程序打开Waze应用程序,传递纬度和经度。
它很好地打开了Waze,但是Waze刚打开,它没有试图找到我通过的地址或纬度/经度。

关于如何使其发挥作用的一些想法?

--- 修改 ---
最后,它工作,使用@SushiHangover的想法,我设法达到了预期的结果。最终的代码在这里:

public static Task<bool> OpenWazeAndroid(decimal latitude, decimal longitude, string address)
        {
            if (IsAndroid())
            {
                try
                {
                    var lat = latitude.ToString().Replace(",",".");
                    var longi = longitude.ToString().Replace(",", "."); 
                    const string wazePrefix = "waze://";
                    Android.Content.Intent intent = new Android.Content.Intent(Android.Content.Intent.ActionView, Android.Net.Uri.Parse(wazePrefix));  
                    string wazeURL = ("https://waze.com/ul?q=" + address + "&ll=" + lat + "," + longi + "&z=8&navigate=yes");
                    wazeURL = wazeURL.Replace(" ", "%20");
                    var resolveInfo = Android.App.Application.Context.PackageManager.ResolveActivi‌​ty(intent, 0);
                    Android.Net.Uri wazeUri;
                    if (resolveInfo != null)
                    {
                        wazeUri = Android.Net.Uri.Parse(wazeURL);
                    }
                    else
                    {
                        wazeUri = Android.Net.Uri.Parse("market://details?id=com.waze");
                    }
                    intent.AddFlags(Android.Content.ActivityFlags.NewTask);
                    intent.SetData(wazeUri);
                    Android.App.Application.Context.StartActivity(intent);

                    return Task.FromResult(true);
                }
                catch (Exception ex)
                {
                    App.Shell.Alert("Erro ao abrir o Waze.\n" + ex.Message);
                    return Task.FromResult(false);
                }

            }
            return Task.FromResult(false);
        }

1 个答案:

答案 0 :(得分:4)

Android上的直接应用链接不尊重链接属性/选项(Waze iOS会这样做),因此请使用网络基本网址(https://waze.com)使用深层链接选项正确打开Waze。

示例:

const string wazeAppURL = "waze://";
var wazeURL = $"https://waze.com/ul?ll={loc[0]},{loc[1]}&navigate=yes";
var intent = new Intent(Intent.ActionView, Android.Net.Uri.Parse(wazeAppURL));
var resolveInfo = PackageManager.ResolveActivity(intent, 0);
var wazeUri = resolveInfo != null ? Android.Net.Uri.Parse(wazeURL) : Android.Net.Uri.Parse("market://details?id=com.waze");
intent.SetData(wazeUri);
StartActivity(intent);