【问题标题】:Xamarin Android Start app using link with parameters使用带有参数的链接的 Xamarin Android 启动应用程序
【发布时间】:2020-03-23 12:05:05
【问题描述】:

我有问题。我创建了一个 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】:

一个完整的 URL Scheme 协议格式由 Scheme、主机、端口、路径和查询组成。结构如下:

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

并在被调用的Activity中接收数据,如:

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

【讨论】:

  • 获取uri参数需要把代码放在哪里?
猜你喜欢
  • 1970-01-01
  • 2018-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多