There have been many questions like this before, and I've tried to implement the answers but it doesn't work on Android 11. I want my flutter app will be started/opened automatically after booting was completed.
this is my receiver MainActivityReceiver.kt
package com.mypackage
import android.content.BroadcastReceiver
import android.content.Context;
import android.content.Intent;
class MainActivityReceiver: BroadcastReceiver() {
override fun onReceive(context: Context, intent: Intent) {
if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
val i = Intent(context, MainActivity::class.java)
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
context.startActivity(i)
}
}
}
and I added some code on AndroidManifest.xml
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<receiver
android:enabled="true"
android:exported="true"
android:name="com.myPackage.MainActivityReceiver"
android:permission="android.permission.RECEIVE_BOOT_COMPLETED">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED" />
<action android:name="android.intent.action.QUICKBOOT_POWERON" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</receiver>
from Flutter app BOOT_COMPLETED receiver doesn't work
No comments:
Post a Comment