参考教程:
https://codinginflow.com/tutorials/android/start-app-on-boot
(本教程的特点是多了
<action android:name="android.intent.action.QUICKBOOT_POWERON" /> )
https://blog.csdn.net/menghaocheng/article/details/79540327
(本教程的特点是多了
<intent-filter android:priority="1000">)
DEBUG:
Error: Element receiver#com.example.iguardonxiaomi8se.OnBootReceiver at AndroidManifest.xml:66:9-73:20 duplicated with element declared at AndroidManifest.xml:33:9-36:48 app main manifest (this file), line 65 Error: Validation failed, exiting app main manifest (this file)
这是因为你通过右击文件夹New - other - Broadcast Receiver 新建一个类后,Android Studio自动帮你在manifest里也写好了一个
<receiver android:name=".OnBootReceiver" android:enabled="true" android:exported="true"></receiver>
如果我再复制粘贴另外一个receiver的话,就会重复了,所以把删掉/合并这个receiver就能解决bug了。