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")
}
}
}
The service starts only if I open my application manually as I've also added logic to start the service in MainActivity.kt.
During boot I've captured the logcat output and found an following error:
TclAppBootManagerImpl: ...calleePkgName = 'com.example.myapp' ... broadcastAction = 'android.intent.action.BOOT_COMPLETED' ... isAutoStart = 'true', isAllow = 'false', reason = 'callee_does't_have_OP_AUTO_START_permission.'
Which means 'callee_does't_have_OP_AUTO_START_permission.'
How to grant this permission (OP_AUTO_START) and rectify the issue?
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