问题描述
我正在使用Xamarin Forms(跨平台)开发应用程序,并且我试图通过我的应用程序打开Waze应用程序,并传递纬度和经度.
它可以很好地打开Waze,但是Waze只是打开,它没有尝试查找我经过的地址或纬度/经度.
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.
string stringUri = @"waze://ul?ll=" + client.Latitude + "," + client.Longitude + "&navigate=yes";
Intent intent = new Intent(Intent.ActionView);
intent.AddFlags(ActivityFlags.NewTask);
intent.SetData(Android.Net.Uri.Parse(stringUri));
Android.App.Application.Context.StartActivity(intent);
关于如何使其工作的一些想法?
Some Ideas on how I make it work?
--- EDIT ---
最后,它使用@SushiHangover的想法进行了工作,我设法达到了预期的结果.最终代码在这里:
---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) {
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);
}
推荐答案
Android上的直接应用程序链接不遵守链接属性/选项(Waze iOS则遵循),因此请使用网络基本URL(https://waze.com
)正确使用使用深层链接选项打开位智.
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.
示例:
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);
这篇关于位智深层链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!