我想用Xamarin for Android编写一个简单的活动,该URL可以共享给(例如,Chrome可以共享我的活动的URL)。如何使用Xamarin Intent过滤器接收URL
这里是我到目前为止有:
[Activity (Label = "LinkToDesktop", MainLauncher = true)]
[IntentFilter (new[] {
Intent.ActionSend,
Intent.CategoryBrowsable,
Intent.CategoryDefault,
})]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
string text = Intent.GetStringExtra ("MyData") ?? "Data not available";
}
}
不幸的是,我的应用程序不会在Chrome的列表中显示出来,当我试图共享。我错过了什么?
编辑,更新后的代码,我以下发布。当我从Chrome浏览器共享时,仍然不会显示为目标。
[Activity (Label = "LinkToDesktop", MainLauncher = true)]
[IntentFilter (new[] { Intent.ActionSend },
Categories = new[] { Intent.CategoryBrowsable, Intent.CategoryDefault })
]
public class MainActivity : Activity
{
protected override void OnCreate (Bundle bundle)
{
base.OnCreate (bundle);
string text = Intent.GetStringExtra ("MyData") ?? "Data not available";
}
protected override void OnNewIntent (Intent intent)
{
base.OnNewIntent (intent);
}
}
我并不担心MyData,因为它甚至没有达到。 – mason
与修正的'IntentFilter'是否达到?我知道用NFC你需要在OnNewIntent方法中获取数据,所以试着重写一下,看看这里是否也是这种情况。 – Cheesebaron
不,仍然不起作用。我用我试过的代码更新了我的问题。 – mason