How can I set up kiosk mode in android tv?

18 Views Asked by At

I have tried to set up a kiosk mode in my activity's onResume method call setupKiosk() function. In android phone, it worked, but in android tv doesn't.

private fun setupKiosk() {
        if (policyManager.isDeviceOwnerApp(packageName)) {
            setupAutoStart()
            stayAwake()
            policyManager.setLockTaskPackages(
                adminComponentName,
                arrayOf(
                    packageName,
                    "com.facebook.katana",
                    "com.whatsapp",
                    "com.google.android.youtube",
                    "com.viber.voip"
                )
            )
        }
        (this).startLockTask()
    }

    private fun setupAutoStart() {
        val intentFilter = IntentFilter(Intent.ACTION_MAIN)
        intentFilter.addCategory(Intent.CATEGORY_HOME)
        intentFilter.addCategory(Intent.CATEGORY_DEFAULT)
        policyManager.addPersistentPreferredActivity(
            adminComponentName,
            intentFilter, ComponentName(packageName, KioskActivity::class.java.name)
        )
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M)
            policyManager.setKeyguardDisabled(adminComponentName, true)
    }

    private fun stayAwake() {
        policyManager.setGlobalSetting(
            adminComponentName,
            Settings.Global.STAY_ON_WHILE_PLUGGED_IN,
            (BatteryManager.BATTERY_PLUGGED_AC
                    or BatteryManager.BATTERY_PLUGGED_USB
                    or BatteryManager.BATTERY_PLUGGED_WIRELESS).toString()
        )
    }

Any suggestions how can I solve it

0

There are 0 best solutions below