Is it possible to turn off tv device via android tv app?

Vadim Eksler picture Vadim Eksler · Jan 30, 2019 · Viewed 7.7k times · Source

For my example I create simple TV app add button "power off" and tried to shut down my emulator where I run it.

First of all i tried to find something in documentation here https://developer.android.com/training/tv/start/hardware#hardware-permissions, but there is no hardware power controls.

After that I tried some android mobile options like here: programmatically set screen to off in android

Such as: WRITE_SETTINGS

Settings.System.putInt(getContentResolver(), Settings.System.SCREEN_OFF_TIMEOUT, 1000);

I think problem here with getting runtime permission that android tv can't resolve.

Also I tried options from here Android: How to turn screen on and off programmatically?

mWakeLock = mPowerManager.newWakeLock(PowerManager.PROXIMITY_SCREEN_OFF_WAKE_LOCK, "tag");
     mWakeLock.acquire();

no effect.

Manipulation with screen brightness also no effect:

params.flags |= LayoutParams.FLAG_KEEP_SCREEN_ON;
params.screenBrightness = 0;
getWindow().setAttributes(params);

Any idea what can I try? Thanks for any help

Answer

shalafi picture shalafi · Jan 30, 2019

Some TVs do have a REST API that you can use to invoke the equivalent of clicks on a remote. I've use it on the Sony Bravia series, but I'm not sure other TVs would have it.

In any case that was brand specific and not related to Android TV itself, so you can't rely on it for all devices. I could not find a system call to do it directly.