AndroidTV api Topic is solved

Others (MiLight, Hue, Toon etc...)
Post Reply
User avatar
Egregius
Posts: 2733
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

AndroidTV api

Post by Egregius » Tuesday 15 May 2018 17:20

Hi All,

I just installed a Nvidia Shield as Mediaplayer. It'll run Netflix, Spotify, Kodi,...
Does anyone know if there's an api available to control Android TV from within domoticz?
When Kodi is started I can do everything I want, but I first need to start Kodi of course.
Would be great to be able to start the Shield, start a application and control pause/playback.

There are several ports listening, none of them display anything in a browser:

Code: Select all

Port Scanning host: 192.168.2.7

	 Open TCP Port: 	6466
	 Open TCP Port: 	6467
	 Open TCP Port: 	8008   		http-alt
	 Open TCP Port: 	8009
	 Open TCP Port: 	9000   		cslistener
	 Open TCP Port: 	9080   		glrpc
	 Open TCP Port: 	34803
portscan is voltooid…
Any ideas?

skybehind
Posts: 35
Joined: Monday 04 April 2016 22:00
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: AndroidTV api

Post by skybehind » Tuesday 15 May 2018 17:47

I don't know if this will help, but it's a guide to build libcec binary on Android

https://www.evernote.com/shard/s426/sh/ ... 6c7cfbd702

User avatar
Egregius
Posts: 2733
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: AndroidTV api

Post by Egregius » Wednesday 16 May 2018 9:08

That's something for controlling devices over HDMI CEC.
I'd rather have a http api, like the json api from Domoticz.
I think the CEC way is mostly arrow up, down etc. Not directly possible the launch apps and stuff like that.

DanM
Posts: 96
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: AndroidTV api

Post by DanM » Wednesday 16 May 2018 10:44

You can control andrid devices using ADB and sending keypress events. Have a search on the forums for my Fire TV status script (Fire TV runs android, so the basic principles are the same.).

Something along these lines ought to get you started.. http://www.aftvnews.com/how-to-remotely ... ment-58950 (Again, this is fire TV not andorid but the priciples are the same)

User avatar
Egregius
Posts: 2733
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: AndroidTV api

Post by Egregius » Wednesday 16 May 2018 14:42

Thank you for that!

First step: Enable ADB in Nvidia Shield (source: https://sites.google.com/site/nvidiashi ... -debugging)

Code: Select all

Enable debugging
1. Goto Settings
2. Go across to About in Device
3. Go down to Build and click on it 10times until it says you are in development mode

ADB over USB
1. Make sure you have performed the above steps "Enable debugging"
2. Goto Settings
3. Go Across to Developer options
4. Go down to Debugging
5. Toggle USB debugging to On

ADB over Network
1. Make sure you have performed the above steps "Enable debugging"
2. Make sure you have performed the above steps "ADB over USB"
3. Toggle Network debugging to On
That went ok, see open ports:

Code: Select all

Port Scanning host: 192.168.2.7
	 Open TCP Port: 	139    		netbios-ssn
	 Open TCP Port: 	445    		microsoft-ds
	 Open TCP Port: 	5555   		personal-agent
	 Open TCP Port: 	6466
	 Open TCP Port: 	6467
	 Open TCP Port: 	8008   		http-alt
	 Open TCP Port: 	8009
	 Open TCP Port: 	9000   		cslistener
	 Open TCP Port: 	9080   		glrpc
	 Open TCP Port: 	38321
Now making a snapshot of my Domoticz install before installing the android adb tools.

Edit:
On my Domoticz debian Jessie:

Code: Select all

apt-get install adb
Try a connection with these commands:

Code: Select all

adb kill-server
adb start-server
adb connect 192.168.2.7
Confirm the connection on the Nvidia Shield and place a checkmark on 'always allow device'.

A first small shell script enables me to handle play/pause from within domoticz (wich was the most important part for me)

Code: Select all

#!/bin/bash
adb start-server
adb connect 192.168.2.7
adb shell input keyevent 85

User avatar
Egregius
Posts: 2733
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: AndroidTV api

Post by Egregius » Wednesday 16 May 2018 16:37

Thank you @DanM :D

Everything working, can control up/down/back etc
Can read the current application, thanks to your script.
Me happy :-)

DanM
Posts: 96
Joined: Thursday 23 October 2014 22:41
Target OS: Raspberry Pi
Domoticz version:
Contact:

Re: AndroidTV api

Post by DanM » Friday 18 May 2018 15:20

You can also launch apps directly with the right ADB Commands.

Code: Select all

start -n com.package.name/com.package.name.ActivityName
You will have to google for the package names, but Ive had success launching netflix, iplayer and Kodi this way. Ill try and look at my code later if I can find some examples.

User avatar
Egregius
Posts: 2733
Joined: Thursday 09 April 2015 12:19
Target OS: Linux
Domoticz version: Beta
Location: Beitem, BE
Contact:

Re: AndroidTV api

Post by Egregius » Friday 18 May 2018 16:25

Sounds great, will try that later ;)

Guess that would be something like this then:

Code: Select all

adb start -n com.package.name/com.package.Netflix.ActivityName
Edit, no should be more like

Code: Select all

adb shell "start -n com.package.name/com.package.name.ActivityName"
but I'm getting "start: must be root"

kllngtme
Posts: 54
Joined: Tuesday 14 June 2016 16:56
Target OS: Raspberry Pi
Domoticz version: Beta
Location: East Coast, USA
Contact:

Re: AndroidTV api

Post by kllngtme » Friday 18 May 2018 17:47

Any way to power off the Shield in this manner as well or check status to see if it's online (other than a ping request to it)

Post Reply

Who is online

Users browsing this forum: No registered users and 7 guests