I want to start my MainActivity
right after device boot. I tried multiple solutions but no one works. Currently, I have this.
AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver android:name="installer.common.InstallerBroadcastReceiver">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
</intent-filter>
</receiver>
InstallerBroadcastReceiver.kt
class InstallerBroadcastReceiver : BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
val i = Intent(context, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
i.putExtra("test", 1)
context.startActivity(i)
}
}
MainActivity.kt
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
if (intent.hasExtra("test")) {
someMethodHere()
}
}
Any suggestion on what can be wrong?
Seems like there is some problem with device (zkteco), i get this error
I/BackgroundManagerService: prevent from boot complete broadcast: com.mypackagename
On other devices i tried, it was working.