androidservicebootsmart-tvbootcompleted

BootReceiver Service Not Starting Automatically on TCL Smart TV After Boot


I've developed a service that should start automatically when Smart TV is started but it is not starting. I've also made my application Device Owner using ADB command. Following is the code of the manifest and BootReceiver Service:

     <receiver android:name=".BootReceiver"
        android:enabled="true"
        android:exported="true">
        <intent-filter>
            <action android:name="android.intent.action.BOOT_COMPLETED" />
            <action android:name="android.intent.action.LOCKED_BOOT_COMPLETED" />
            <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            <action android:name="com.htc.intent.action.QUICKBOOT_POWERON" />
            <action android:name="android.intent.action.MY_PACKAGE_REPLACED" />
        </intent-filter>
    </receiver>

    =====================================================================================

    class BootReceiver : BroadcastReceiver() {

    private val TAG = "MyApp"

    override fun onReceive(context: Context, intent: Intent) {
        Log.d(TAG, "Boot completed received: ${intent.action}")

        if (intent.action == Intent.ACTION_BOOT_COMPLETED ||
            intent.action == Intent.ACTION_LOCKED_BOOT_COMPLETED||
            intent.action == Intent.ACTION_MY_PACKAGE_REPLACED) {

            Log.d(TAG, "Trying to start monitoring service")
            //context.startService(Intent(context, SettingsMonitorService::class.java))

            val serviceIntent = Intent(context, SettingsMonitorService::class.java)
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
                context.startForegroundService(serviceIntent)
            } else {
                context.startService(serviceIntent)
            }
            ///Toast.makeText(this, "Monitoring started", Toast.LENGTH_SHORT).show()
            Log.d(TAG, "Monitoring service started")

          }
        }
      }

Solution

  • TCL tv's have an additional app installed called Safety Guard that manages auto-start permissions for apps for some reason. You need to make sure that your app isnt being prevented by that.

    Go to Safety Guard -> Permission Shield -> Auto Launch Permission and change the Auto Manager to Closed then change your app manually to Open