0

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?

Son Truong
  • 13,661
  • 5
  • 32
  • 58
Coldnight
  • 107
  • 13

2 Answers2

0

try to split your intent-filter

    <intent-filter>
        <action android:name="android.intent.action.QUICKBOOT_POWERON" />
    </intent-filter>
    <intent-filter>
        <action android:name="android.intent.action.BOOT_COMPLETED" />
    </intent-filter>
snachmsm
  • 17,866
  • 3
  • 32
  • 74
0

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.

Coldnight
  • 107
  • 13