Search code examples
androidandroid-tvlaunchbootcompleted

How to launch app from outside with BOOT_COMPLETED in android 10 and above versions


How to launch application, if my device is Android tv? in android version of 9 and lower this code workid, but higher versions the application do not launching. Is any solutions?

`class BootReceiver : BroadcastReceiver() {
    override fun onReceive(context: Context, intent: Intent) {
        if (intent.action == Intent.ACTION_BOOT_COMPLETED) {
            Log.w("bootbroadcastpoc", "starting service...");

            if (Intent.ACTION_BOOT_COMPLETED.equals(intent.getAction())) {
                Toast.makeText(context, "Boot completed", Toast.LENGTH_SHORT).show();

                val intent = Intent(context, KioskActivity::class.java)
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
                context.startActivity(intent)


            }
        }
    }
}`

I also tried to start the service and from the service launch my application, but that also did not help.


Solution

  • As Android Developers page, Android 10 (API level 29) and higher place restrictions on when apps can start activities when the app runs in the background. There are several solutions, but I think the easiest way is to request SYSTEM_ALERT_WINDOW permission.