Xamarin Android Start app using link with parameters

断了今生、忘了曾经 提交于 2020-01-16 11:32:32

问题


I have a problem. I created a IntentFilter so my app launches when clicked on a specific link. Here is my IntentFilter:

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

And here is the link:

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

But how can I pass a parameter (integer) in that link and how can I use that parameter in my C# code?


回答1:


A complete URL Scheme protocol format consists of Scheme, host, port, path, and query. The structure is as follows:

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

and receive data in the called Activity like:

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

the link :

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

get the parameter :

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


来源:https://stackoverflow.com/questions/59078568/xamarin-android-start-app-using-link-with-parameters

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