1、继承BroadcastReceiver类,在OnReceive中做开机自启动(或者其他事情),
namespace Test.Droid
{
public class BootReceiver:BroadcastReceiver
{
public override void OnReceive(Context context, Intent intent)
{
//Toast.MakeText(context, "接收到开机广播", ToastLength.Long).Show();
Intent _intent = context.PackageManager.GetLaunchIntentForPackage(包名);
context.StartService(_intent);
}
}
}
2、添加权限和配置,AndroidManifest文件配置如下:
<application>
<receiver android:enabled="true" android:name="test.droid.BootReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</receiver>
</application>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission>
Copyright © 广州京杭网络科技有限公司 2005-2024 版权所有 粤ICP备16019765号
广州京杭网络科技有限公司 版权所有