Waze Deep Links

烈酒焚心 提交于 2019-12-07 06:25:50

问题


I'm developing an App using Xamarin Forms (cross platform), and im trying to open Waze app from my app, passing latitude and longitude.
It opens Waze very well, but Waze just open, it didn't try to find the address or the latitude/longitude that I passed.

Some Ideas on how I make it work?

---EDIT---
Finally, it WORKED, using the idea from @SushiHangover, i managed to achieve the desired result. The final code is here:

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:


The direct app link on Android does not respect the link properties/options (Waze iOS does), so use the web base url (https://waze.com) to properly open Waze with the deep link options.

Example:

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);


来源:https://stackoverflow.com/questions/47358194/waze-deep-links

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!