[Xamarin Android Start应用程序,使用带有参数的链接

问题描述 投票:0回答:1

我有问题。我创建了一个IntentFilter,以便在单击特定链接时启动我的应用程序。这是我的IntentFilter:

[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Android.Content.Intent.CategoryBrowsable },
DataScheme = "myapplication.app"
)]

这是链接:

<a href='myapplication.app://'>here</a>

但是如何在该链接中传递参数(整数),以及如何在我的C#代码中使用该参数?

c# xamarin android-intent xamarin.android intentfilter
1个回答
0
投票

完整的URL Scheme协议格式包括Scheme,主机,端口,路径和查询。结构如下:

<scheme>://<host>:<port>/<path>?<query>

并在调用的活动中接收数据,如:

[IntentFilter(new[] { Intent.ActionView },
Categories = new[] { Intent.CategoryDefault, Intent.CategoryBrowsable },
DataScheme = "urlschemetest2",
DataHost = "testurl.com")]

链接:

<a href="urlschemetest2://testurl.com/?firstname=john&lastname=doe">Test Opening App</a>

获取参数:

 protected override void OnNewIntent(Intent intent)
 {
   Android.Net.Uri uri  = Intent.Data;
   if(uri != null)
   {
      string firstName = uri.GetQueryParameter("firstname");
      string lastName = uri.GetQueryParameter("lastname");
   }
   base.OnNewIntent(intent);
 }
© www.soinside.com 2019 - 2024. All rights reserved.