I'd like my Flutter/Kotlin application to be able to launch and display automatically when my Android 9 and higher device starts up.
I've tried the broadcastReceiver but it doesn't work, I receive the logs but it doesn't visually launch the application.
I add autorization to my Manifest
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" /> and declaration of my BroadcastReceiver
<receiver android:name=".BootBroadcastReceiver" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> <category android:name="android.intent.category.DEFAULT" /> </intent-filter> </receiver> I created two classes, a class BroadcastReceiver who get boot_complete
import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager import androidx.work.WorkRequest class BootBroadcastReceiver : BroadcastReceiver() { override fun onReceive(context: Context?, intent: Intent?) { if (intent != null) { if(intent.action == Intent.ACTION_BOOT_COMPLETED) { Log.d("BootBroadcastReceiver", "Boot completed. Scheduling app launch.") // Planifier un travail pour démarrer l'application après un délai val workRequest: WorkRequest = OneTimeWorkRequest.Builder(AppLaunchWorker::class.java).build() if (context != null) { WorkManager.getInstance(context).enqueue(workRequest) } } } } } and a class AppLaunchWorker who launch the app
import android.content.Context import android.content.Intent import androidx.work.Worker import androidx.work.WorkerParameters import io.flutter.embedding.android.FlutterActivity class AppLaunchWorker(context: Context, workerParams: WorkerParameters) : Worker(context, workerParams) { override fun doWork(): Result { // Lancer FlutterActivity après que le système ait démarré val launchIntent = FlutterActivity.createDefaultIntent(applicationContext) launchIntent.flags = Intent.FLAG_ACTIVITY_NEW_TASK // Nécessaire pour démarrer l'activité depuis un contexte non interactif applicationContext.startActivity(launchIntent) // Retourner un résultat de succès return Result.success() } } i can see the log but the app dont open visually
Log.d("BootBroadcastReceiver", "Boot completed. Scheduling app launch.")
android.permission.ACTION_MANAGE_OVERLAY_PERMISSIONandroid.permission.SYSTEM_ALERT_WINDOWdid you granted the permission? look like your problem is similar to stackoverflow.com/questions/72972225/…