赞
踩
新建一个Xamarin.Forms工程:Demo,你的解决方案里会出现两个工程分别是Demo和Demo.Android
在Demo.Android上点右键->添加->新建项->广播接收器
这样就添加了一个Receiver,把它改名叫BootReceiver.cs
BootReceiver.cs里面的代码如下
[BroadcastReceiver(Enabled = true, Exported = true)]
[IntentFilter(new[] { Intent.ActionBootCompleted }, Priority = (int)IntentFilterPriority.HighPriority)]
public class BootReceiver : BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
Intent toIntent = context.PackageManager.GetLaunchIntentForPackage(context.PackageName);
context.StartActivity(toIntent);
}
}
在Demo.Android上点右键->属性->Android清单
下面所需权限里把 RECEIVE BOOT COMPLETED 勾上
完成!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。