Reputation: 887
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
Upvotes: 1
Views: 9185
Reputation: 479
On an Nvidia Shield with Oreo the settings app has buttons like "Sleep now" and "Restart". If I were you I would take a look at settings app's source code and try to find the APIs that are being called by these buttons. Maybe taking a look at this will tell you at least where to start.
Upvotes: 1
Reputation: 3996
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.
Upvotes: 1