tronikos / androidtvremote2

A Python library implementing the Android TV Remote protocol v2
Apache License 2.0
57 stars 9 forks source link

How to launch any app such as Kodi #17

Closed albaintor closed 4 months ago

albaintor commented 6 months ago

Hi,

Actually this is not possible to launch any app if no url scheme is defined, and this is not possible to retrieve the list of installed apps.

The Nvidia shield tv app can retrieve the app list and launch any app as in the capture below. Is it using the same remote service as you do ? image

Also I saw on another python implementation (but I couldn't run it due to old dependencies) : https://github.com/farshid616/Android-TV-Remote-Controller-Python There is a "send_lunch_app_command" method that could launch any application with an example : "intent:#Intent;component=com.netflix.ninja/.MainActivity;end". I couldn't reproduce it on your integration

Thank you for your help, I can help for the implementation

Here is another screenshot (with kodi) : Capture décran  2024-03-14 à 10 09 07 (002)

tronikos commented 6 months ago

That's right. You can only send URLs which means you can't run apps such as KODI that don't have one registered. But you should be able to use the Android ADB integration for such apps.

I believe the NVIDIA SHIELD TV is using a very similar protocol but extended for additional functionality. If you want to reverse engineer that and implement it, take a look at:

tronikos commented 6 months ago

I forgot to mention that https://github.com/farshid616/Android-TV-Remote-Controller-Python is for the old V1 protocol. It's also linked in this repo under credits.

albaintor commented 6 months ago

Thank you for your feedback. I would like to avoid adb as this is intended to be used by the Unfolded Circle remote control which holds an android tv integration based on your library so ADB is not possible and requires additional administration. Adb is slow by the way

tronikos commented 4 months ago

I don't use adb either because it's slow. That's the reason I created this library and the Home Assistant integration. Did you open a feature request to Kodi? They just need to add the following lines in their manifest:

            <intent-filter>
                <action android:name="android.intent.action.VIEW"/>
                <category android:name="android.intent.category.DEFAULT"/>
                <data android:scheme="kodi"/>
            </intent-filter>

and then we will be able to open it with kodi://

Note the above was based on what Plex is using, see https://community.home-assistant.io/t/android-tv-remote-app-links-deep-linking-guide/567921

It will be faster to just send them a PR with these changes.

tronikos commented 4 months ago

From https://github.com/tronikos/androidtvremote2/issues/20

I submitted a PR to Kodi's team to have deeplinks, meanwhile we found a workaround with this URL "market://launch?id=org.xbmc.kodi"

Good to hear! Can you link to the PR? I assume the workaround opens Play Store and you have to select open to launch the app? Could you edit https://community.home-assistant.io/t/android-tv-remote-app-links-deep-linking-guide/567921 and maybe even https://www.home-assistant.io/integrations/androidtv_remote/ with this workaround? This seems very useful especially since it can work on any installed app.

albaintor commented 4 months ago

The workaround opens Kodi directly without going through the store.

Finally the PR is on the form they don't accept feature request through GitHub. https://forum.kodi.tv/showthread.php?tid=377296

Drafteed commented 4 months ago

I submitted a PR to Kodi's team to have deeplinks, meanwhile we found a workaround with this URL "market://launch?id=org.xbmc.kodi"

Wow, great way to run any application by app_id (package_name)! I tried it on my devices - it allows you to run any application, not even from the Google Play Store, without any confirmation. You don’t have to worry about supporting deep links by app.

TiviMate:
market://launch?id=ar.tvplayer.tv

SmartTube (not from Play Store):
market://launch?id=com.teamsmart.videomanager.tv

Twitch:
market://launch?id=tv.twitch.android.app

Steam Link:
market://launch?id=com.valvesoftware.steamlink

@tronikos Maybe we should add a handler to the media_player.play_media service in HA integration?

service: media_player.play_media
data:
  media_content_type: app
  media_content_id: com.teamsmart.videomanager.tv
target:
  entity_id: media_player.living_room_tv
tronikos commented 4 months ago

Thanks for confirming this trick actually works on all apps. I want to change this library to add market://launch?id= if the link doesn't have scheme and update all documentation. I'll try to do that tonight.

Drafteed commented 4 months ago

I want to change this library to add market://launch?id= if the link doesn't have scheme and update all documentation. I'll try to do that tonight.

I would rather suggest implementing this as a separate (sub)service. It seems to me that trying to detect the presence of a scheme ( :// substring i think) is not a very elegant solution. Could there be schemes that we don't know about that don't contain ://?

My suggestion: https://github.com/home-assistant/core/compare/dev...Drafteed:home-assistant:atvremote-play-media-app?expand=1

I can push it now.

Drafteed commented 4 months ago

Core PR: https://github.com/home-assistant/core/pull/116896

tronikos commented 4 months ago

It seems to me that trying to detect the presence of a scheme ( :// substring i think) is not a very elegant solution. Could there be schemes that we don't know about that don't contain ://?

Scheme is required for deep links so deep links will always have ://. In addition, package names can't have :// in them.

Drafteed commented 4 months ago

Scheme is required for deep links so deep links will always have ://

uri:content is also valid URI, eg. mailto:example@example.com, tel:+123455678, geo:55.79378663446035,49.11699501723111, sms:+18432776410?body=hello%20test, does not contain ://, but can handled by the Android TV service and your lib before 1.x.x.

//example.com is also valid URL (https://www.paulirish.com/2010/the-protocol-relative-url/). magnet:?xt=urn:btih:19ab7ff03d14dda05a15445374ad68bf55ada321&dn=Name is valid magnet link. [isbn:0393315703] is also valid URI (https://en.wikipedia.org/wiki/CURIE).

https://www.iana.org/assignments/uri-schemes/uri-schemes.xhtml

image

tronikos commented 4 months ago

Thanks. https://github.com/tronikos/androidtvremote2/commit/c5d7292e8efe6201854884d8402572398ee11c2a should take care of most of these edge cases.

Dillton commented 3 months ago

Hello @tronikos,

finally opening Kodi is working thank you very much however I found one app used in Czechia as IPTV service which won't open with market://launch?id=cz.sledovanitv.android or just cz.sledovanitv.android. App name is SledovaniTV.

What happens is only the store page of the app is opened. Do you or anyone have any idea why?

tronikos commented 3 months ago

No sorry