问题
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