CrossLauncher icon indicating copy to clipboard operation
CrossLauncher copied to clipboard

Use TV Launch Intent to launch TV Apps

Open EmiyaSyahriel opened this issue 1 year ago • 23 comments

Discussed in https://github.com/EmiyaSyahriel/CrossLauncher/discussions/48

Originally posted by Quackdoc August 27, 2023 Launchers can get the TV/Leanback intent using getLeanbackLaunchIntentForPackage(packageName) This would allow booting to the TV version of an application (for example VLC) if the application supports a TV interface and has an appropriate intent. This would be quite useful as many applications when launched like this launch into a controller optimized interface which fits in with the promoted intended use case for this app.

a good example of an application where this helps is dolphin emulator, since the touch UI for dolphin is very lack luster. so oppening the TV/Leanback version helps a lot

documentation here https://developer.android.com/reference/android/content/pm/PackageManager#getLeanbackLaunchIntentForPackage(java.lang.String)

EmiyaSyahriel avatar Aug 27 '23 10:08 EmiyaSyahriel

Implemented at commit 05c95a12d84a7c605cfb6714c5c1db18021e024c , Can be set at Settings > System Settings > Prioritize TV Intent, it is defaults to Yes if the device is detected as TV.

Need help to test, I do not have a TV to test and only have limited storage space to use deploy a TV emulator. Testing on tablet and phone resulting Dolphin and VLC to starts at it's phone layout instead of TV.

EmiyaSyahriel avatar Aug 27 '23 17:08 EmiyaSyahriel

Tested, Alpha 20230702_1117P, on Android TV 10 with remote and ~~everything~~ seemed to function correctly.


Edit: After more testing on physical TV box with remote control, I did come across a few issues thus far:

  1. Settings category
  • Display Settings -> Display Button Type = Doesn't save choice when closing and reopening app
  • Display Settings -> Show Network Name = Doesn't save choice when closing and reopening app
  • System Settings -> Rearrange Category = R/L navigation skips, moves 2 spaces instead of 1
  • System Settings -> Show hidden apps = Doesn't show system apps in apps list when toggled yes
  • Android System Settings -> Apps & notifications -> Default apps = No function
  • Android System Settings -> Privacy = Opens factory reset (careful!)
  • Android System Settings -> Accessibility = "You don't have an app that can do this" message
  • Android System Settings -> Any menu item with an internal submenu = Doesn't save previous tab when navigating back
  1. Apps category
  • Within the list of installed apps, there's no function to open an app submenu like on mobile
  1. Not all categories present
  • Only 4 of 7 categories are available

Note: Fast scroll works great by holding down R/L/Up/Down on remote control.

Overall, most of the app seems to function correctly and I believe it has great potential to be an unique Android TV launcher.

DarkCrypt avatar Aug 29 '23 10:08 DarkCrypt

interesting that it's not seeming to work on tablet/phone, Im currently testing via waydroid and it's not working here either

Quackdoc avatar Aug 29 '23 18:08 Quackdoc

ok, I think I found the issue, I was able to get it to work on tablet/phone's using this hack, apologize im not a kotlin dev, so im not sure the proper way to fix it, but it seems like it will always prioritze the "phone" launch option on tablet/phone devices, Im not sure if this is something that was hidden due to leanback.

Im not sure if val tv = vsh.packageManager.getLeanbackLaunchIntentForPackage(resInfo.activityInfo.packageName) will fail elegantly or not, but I needed to pull it out of the sdk if statement because compiler was complaining about it

diff --git a/launcher_app/src/main/java/id/psw/vshlauncher/types/items/XMBAppItem.kt b/launcher_app/src/main/java/id/psw/vshlauncher/types/items/XMBAppItem.kt
index ba38e53..cadae14 100644
--- a/launcher_app/src/main/java/id/psw/vshlauncher/types/items/XMBAppItem.kt
+++ b/launcher_app/src/main/java/id/psw/vshlauncher/types/items/XMBAppItem.kt
@@ -492,9 +492,10 @@ class XMBAppItem(private val vsh: VSH, val resInfo : ResolveInfo) : XMBItem(vsh)
             try{
                 val intents = arrayListOf<Intent?>()
                 val phone = vsh.packageManager.getLaunchIntentForPackage(resInfo.activityInfo.packageName)
+                val tv = vsh.packageManager.getLeanbackLaunchIntentForPackage(resInfo.activityInfo.packageName)
 
                 if (sdkAtLeast(21)) {
-                    val tv = vsh.packageManager.getLeanbackLaunchIntentForPackage(resInfo.activityInfo.packageName)
+                    //val tv = vsh.packageManager.getLeanbackLaunchIntentForPackage(resInfo.activityInfo.packageName)
                     if(vsh._prioritizeTvIntent){
                         intents.addAllV(tv, phone)
                     }else{
@@ -507,7 +508,15 @@ class XMBAppItem(private val vsh: VSH, val resInfo : ResolveInfo) : XMBItem(vsh)
                 var launched = false
                 for (intent in intents){
                     if(intent != null){
-                        vsh.startActivity(phone)
+                        if (sdkAtLeast(21)) {
+                            if(vsh._prioritizeTvIntent){
+                                vsh.startActivity(tv)
+                            }else{
+                                vsh.startActivity(phone)
+                            }
+                        } else {
+                            vsh.startActivity(phone) 
+                        }
                         launched = true
                         break
                     }

Quackdoc avatar Aug 29 '23 18:08 Quackdoc

interesting that it's not seeming to work on tablet/phone, Im currently testing via waydroid and it's not working here either

I'm also testing on my phone(Android 13) and it works but I experience many of the issues I commented above about Android TV. I did notice that it does somewhat matter where you touch on a touchscreen in order to navigate.

Note: Launching apps from the Apps category(apps list) worked correctly on Mobile and TV.

DarkCrypt avatar Aug 30 '23 01:08 DarkCrypt

@DarkCrypt

  • System Settings -> Show hidden apps = Doesn't show system apps in apps list when toggled yes

It seems that I have to update the description to make it more clearer. That toggle, if set to "Yes", is only supposed to show the apps that is set to be hidden by using the "Is Hidden" toggle in the "App Info" dialog in the apps' submenu (which is currently inaccessible from TV UI, according to your report).

About the Apps' submenu, It is bound to both Keyboard's Tab Key (KEYCODE_TAB) and ContextMenu Key (KEYCODE_MENU, Physically at the left of the Right Ctrl Key). I've assumed that Remocon's Menu key behaves the same as ContextMenu key, Am I wrong?

And also, after looking around some online marketplace, I noticed that some model of Android TV Remocon didn't have a Menu key (I assumed that yours either don't have it, kept only for OS use or sends different KeyCode), How do you access common apps menu then?

  • Android System Settings -> Apps & notifications -> Default apps = No function
  • Android System Settings -> Privacy = Opens factory reset (careful!)
  • Android System Settings -> Accessibility = "You don't have an app that can do this" message

Seems like Android TV uses some of the Settings intent for different purpose, have to change it accordingly. And also, my current implementation of this menu is that if the Device/ROM did not support this setting, it should not be accessible , I need to investigate it why "Default Apps" and "Accessiblity" is still there even thought it shouldn't.

EmiyaSyahriel avatar Sep 01 '23 07:09 EmiyaSyahriel

@EmiyaSyahriel

  • System Settings -> Show hidden apps = Doesn't show system apps in apps list when toggled yes

It seems that I have to update the description to make it more clearer. That toggle, if set to "Yes", is only supposed to show the apps that is set to be hidden by using the "Is Hidden" toggle in the "App Info" dialog in the apps' submenu (which is currently inaccessible from TV UI, according to your report).

You're present implementation is probably ok the way it is. It's my fault that I misunderstood. After reading your reply and thinking about this a little more, even if there was a way to show system apps the option would of been under the Android System Settings category instead of the System Settings category. If I was able to access the apps submenu I would've understood (should of understood anyway since I was able to access with Mobile, duh!).

About the Apps' submenu, It is bound to both Keyboard's Tab Key (KEYCODE_TAB) and ContextMenu Key (KEYCODE_MENU, Physically at the left of the Right Ctrl Key). I've assumed that Remocon's Menu key behaves the same as ContextMenu key, Am I wrong?

I would also assume that Remocon's Menu key behaves the same as ContextMenu key as long as there's a Menu key present.

And also, after looking around some online marketplace, I noticed that some model of Android TV Remocon didn't have a Menu key (I assumed that yours either don't have it, kept only for OS use or sends different KeyCode), How do you access common apps menu then?

Correct, my remote control doesn't have a Menu key whatsoever. It's the old version of the Google TV remote before their recent upgraded version (which appears to have even less buttons). I don't think a common apps menu exists on the device, the only way to get to the list of installed apps is within the Homescreen menus by holding down the Home button. The only other way to see the installed apps is within the System Settings -> Apps.

A possible fix to open the Apps submenu without the use of a Menu key would be to long press the Enter/Select key. This is an option present on the Homescreen menus which opens a small dropdown submenu.

This is a button diagram of the remote control to help you understand:

Onn_Remote_Control

  • Android System Settings -> Apps & notifications -> Default apps = No function
  • Android System Settings -> Privacy = Opens factory reset (careful!)
  • Android System Settings -> Accessibility = "You don't have an app that can do this" message

Seems like Android TV uses some of the Settings intent for different purpose, have to change it accordingly. And also, my current implementation of this menu is that if the Device/ROM did not support this setting, it should not be accessible , I need to investigate it why "Default Apps" and "Accessiblity" is still there even thought it shouldn't.

The Default Apps option should not be present but the Privacy and Accessibility option should. The Privacy option needs to open the correct settings page instead of the Factory Reset page. The Accessibility option needs to open the Accessibility settings page because it does exist on the device.

Note: I'm now testing the app on 3 completely different devices: Android TV 10 (w/remote control), Android 13 (Mobile), and WSA (PC).

DarkCrypt avatar Sep 02 '23 05:09 DarkCrypt

@DarkCrypt what brand is Android TV? I cannot find any trace of Accessibility activity on Android 10 Tv AOSP Settings manifest. in the newer version of Android Tv OS settings, they did have some, but all of them were prefixed with oemlink, possibly it is the responsibility of the manufacturer instead to implement them.

As for Privacy settings, the intent is actually correct, but on the Android 10 Tv AOSP source code, it is redirected directly to Factory Reset page. is the actual privacy settings really there?

May I ask you to check is there any intent associated with the Settings activity page on your TV using Activity Launcher app?

EmiyaSyahriel avatar Jan 03 '24 10:01 EmiyaSyahriel

@EmiyaSyahriel I installed Activity Launcher app...

what brand is Android TV?

It's the old version of Walmart's Onn 4k TV box, it's talked about in this XDA post.

I cannot find any trace of Accessibility activity

There's an Android Accessibility Suite which includes many activities.

As for Privacy settings, the intent is actually correct, but on the Android 10 Tv AOSP source code, it is redirected directly to Factory Reset page. is the actual privacy settings really there?

I was wrong, this is ok as is. I didn't find any Privacy settings but there is Privacy Activity which does redirect to the Factory Reset page like you said.

May I ask you to check is there any intent associated with the Settings activity page on your TV using Activity Launcher app?

There's many activities.

DarkCrypt avatar Jan 07 '24 21:01 DarkCrypt

@DarkCrypt

It's the old version of Walmart's Onn 4k TV box, it's talked about in this XDA post.

From what I read, it is an AOSP-based Android TV box, not much modification done by the manufracturer (e.g Samsung TV), therefore it should be similar to Android TV ROM that's built in to Android Studio, Am I right?

There's an Android Accessibility Suite which includes many activities.

From what I know, Android Accessibility Suite (on phone) gives standardized list of accessibility services that can be configured and activated from the Accessibility Settings page in Settings app/panel, each have it's own one or two activities, and by itself have no main activity, at least on phones I have.

Is there any Accessibility Setting page that can be acessed directly from Settings panel? Or at least any activity that is the Accessibility Settings when launched using Activity Launcher? Or the Accessibility Suite can be launched by itself in TV?

EmiyaSyahriel avatar Jan 07 '24 22:01 EmiyaSyahriel

@EmiyaSyahriel

From what I read, it is an AOSP-based Android TV box, not much modification done by the manufracturer (e.g Samsung TV), therefore it should be similar to Android TV ROM that's built in to Android Studio, Am I right?

Correct, the box is basically a rebranded AOSP-based version of Google's development box. The ui has been updated beyond the stock AOSP which mostly resembles Android TV 13 within Android Studio (even though the box still says Android TV 10). I looked at Android TV 10, 11, 12, 13, and 14 within Android Studio's emulator to attempt to compare.

From what I know, Android Accessibility Suite (on phone) gives standardized list of accessibility services that can be configured and activated from the Accessibility Settings page in Settings app/panel, each have it's own one or two activities, and by itself have no main activity, at least on phones I have.

This appears to be the same for Android TV.

Is there any Accessibility Setting page that can be acessed directly from Settings panel?

Yes, it can be reached by going to Settings -> Device Preferences -> Accessibility. The Android TV roms within Android Studio work the same.

Or at least any activity that is the Accessibility Settings when launched using Activity Launcher?

Looking within the Activity Launcher app for anything that says Accessibility, almost every activity falls under the Android Accessibility Suite. I don't see anything for main activity like you said.

Or the Accessibility Suite can be launched by itself in TV?

No, I don't find a way to launch the Android Accessibility Suite by itself. Within the app info there's only "Force stop", "Uninstall updates", and "Disable". No option to "Open".


I have another open source launcher installed called Projectivity Launcher. This launcher has an option to access the Accessibility Settings but when I try to access this I receive "You don't have an app that can do this" message. Then the launcher instantly redirects me to the Settings panel.

This seems like the best way to implement the option since we're unable to access directly.

DarkCrypt avatar Jan 12 '24 06:01 DarkCrypt

@DarkCrypt Hmm.. looks like we will keep hitting dead ends if we keep on finding how to open the Accessibility Settings page directly using intent this way. Your suggestion about how the Projectivity Launcher handles this, it might be an "implementation shortcut", but seems okay to me. Shall we go with it?

EmiyaSyahriel avatar Jan 12 '24 07:01 EmiyaSyahriel

@EmiyaSyahriel Yes, I think so. So far this implementation seems like the best possibility. Even though the function opens the Settings panel instead of directly, it's still easy for the user to navigate to the Accessibility Settings just by scrolling down.

Edit: Just correcting myself. Settings -> Device Preferences -> Scroll down to Accessibility Settings.

DarkCrypt avatar Jan 12 '24 09:01 DarkCrypt

@DarkCrypt The new setting shortcut item implementation is available in the latest Action Build. can you check it?

I added something to the implementation though, instead of bringing user directly to main settings page, a confirmation dialog will be shown, informing them that "This launcher cannot open that specific setting page and will redirect them to the main settings page instead".

Something like this: Screenshot_20240116-002113

Open Invalid Page is just a testing shortcut from launcher's Debug Menu, Pardon my wallpaper tho 😅

EmiyaSyahriel avatar Jan 15 '24 17:01 EmiyaSyahriel

@EmiyaSyahriel I installed the lastest Action Build (61) from the above link.

I still have the same issue. When I attempt to open the Accessibility Settings page all I get is the toast message "You don't have an app that can do this". The implemented confirmation dialog does not show.

Open Invalid Page is just a testing shortcut from launcher's Debug Menu, Pardon my wallpaper tho 😅

I did try Open Invalid Page within the Debug Settings. After confirming, it does open the Settings page.

DarkCrypt avatar Jan 15 '24 20:01 DarkCrypt

@DarkCrypt I removed the Exception filter for the dialog to appear, it previously only when it get ActivityNotFoundException but now it catches all and displays what exception that triggers the dialog. Can you check the latest Action Build once again?

EmiyaSyahriel avatar Jan 16 '24 03:01 EmiyaSyahriel

@EmiyaSyahriel Action Build (62) has same issue as (61). All I get is the toast message, no confirmation dialog.

DarkCrypt avatar Jan 16 '24 04:01 DarkCrypt

@DarkCrypt Is it a Toast from Android (usually screen bottom or top left) or inside CrossLauncher (Top-right, PS3 Style)? I don't remember calling Android Toast around the Launcher's Setting Shortcut code.

EmiyaSyahriel avatar Jan 16 '24 05:01 EmiyaSyahriel

@EmiyaSyahriel It's a toast message from Android (bottom of screen). Don't mind the mouse pointer.

Screenshot from Android TV (Action Build 62): CLScreenshot-Toast-Message

DarkCrypt avatar Jan 16 '24 06:01 DarkCrypt

@DarkCrypt If that's the case then I'm pretty much can't do anything about it since Android did not give any info to the launcher regarding this, all the launcher know is this call is success.

Looks like I have to find the source of Projectivity Launcher (or even decompile it) to at least know how they do this and make a similar code.

EDIT 2 : I've looked the code, the developer of Projectivity Launcher relies on this logic:

  1. Launcher tries to open the setting page and make a schedule to open main settings page
  2. If error, open the main setting page right away and cancel the schedule
  3. If the launcher is not focused anymore (because Setting page is successfully opened), cancel the schedule.
  4. After a certain time when is not canceled, schedule ran and the main settings page will be opened.

That's the gist of it. But using this method is very risky since Android can become very slow, But I'd like to know how is your opinion on this, and shall we do it this way?

EmiyaSyahriel avatar Jan 16 '24 09:01 EmiyaSyahriel

@EmiyaSyahriel Interesting, I don't like the idea of being risky.

To refresh my memory, I tried this out again with Projectivity Launcher. They do have 2 dialog screens prior to attempting to access the Accessibility Settings and their own toast message as well (there's also the Android toast message). The entire process seems snappy so I'm not sure what to think. I did a short screen recording so you can see for yourself.

Screen recording from Android TV:

https://github.com/EmiyaSyahriel/CrossLauncher/assets/121076677/78472245-9c26-4889-8c0f-1f32348cb0ad

DarkCrypt avatar Jan 17 '24 23:01 DarkCrypt

@DarkCrypt I implemented it anyway, almost exactly like how they implement it, can you check the Latest Action once again?

EmiyaSyahriel avatar Jan 21 '24 13:01 EmiyaSyahriel

@EmiyaSyahriel Unfortunately, the implementation still isn't working (Action Build 64). The app appears to make an attempt but fails. See screen recording.

Screen recording Android TV (Action Build 64):

https://github.com/EmiyaSyahriel/CrossLauncher/assets/121076677/b6e39f45-d4cb-4fd4-9425-321a46678c09

DarkCrypt avatar Jan 21 '24 19:01 DarkCrypt