VeryEasy的开机自启动
Crazy Coding
Manifest.xml
<application
...>
...
<!--BroadCastReceiver-->
<receiver
android:name=".MainReceiver"
android:enabled="true"
android:exported="true">
<intent-filter android:priority="1000">
<action android:name="android.intent.action.BOOT_COMPLETED" />
</intent-filter>
</receiver>
</application>
Receiver
class MainReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
val action = intent!!.action
if (TextUtils.equals(action, Intent.ACTION_BOOT_COMPLETED)) {
val i = Intent(context, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context!!.startActivity(i)
}
}
}
Bingo~