1.写一个类继承BroadcastReceiver
public class BootReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent arg1) {
// TODO Auto-generated method stub
Intent i = new Intent(context, MainActivity.class);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(i);
}
}
2.在mainfast中注册service (加权限)
<receiver android:name="com.example.li.BootReceiver"
android:enabled="true"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"></action>
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
</application>
app开机自启动
最新推荐文章于 2024-07-29 17:57:39 发布