Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can I launch an Android widget from within Termux? #1399

Closed
bitcoinmeetups opened this issue Dec 27, 2019 · 13 comments
Closed

How can I launch an Android widget from within Termux? #1399

bitcoinmeetups opened this issue Dec 27, 2019 · 13 comments

Comments

@bitcoinmeetups
Copy link

bitcoinmeetups commented Dec 27, 2019

How can I launch an Android widget from within Termux?

Let's say another Android app has a widget (e. g. Automate). How can I write a Termux script which launches that widget?

@AbdullahM0hamed
Copy link

Find out the activity that gets launched, and then use am start -n <package>/<activity>

@SDRausty

This comment was marked as spam.

@AbdullahM0hamed
Copy link

@SDRausty Not sure if the example you provided was a counter to what I said, so I'm just going to clarify that I meant something along the lines of

am start -n com.termux/com.termux.app.TermuxActivity

Screenshot_20191227-234932_Termux

@SDRausty

This comment was marked as spam.

@AbdullahM0hamed
Copy link

I suspect that it calls the existing instance if it's already open, and a new instance if it isn't.

Below is a screenshot of me opening chrome (the first time chrome was already open, and the second time it was closed):

Screenshot_20191228-001015_Termux

@bitcoinmeetups
Copy link
Author

Hi. I think with Android "apps with shortcuts" does not mean what it would normally mean. Most apps have icons that you click on the homescreen to start them. But that's not what I'm looking for. Actually I should have said widgets. I got confused because the widgets are also sometimes referred to as shortcuts.

Anyway, I'm looking specifically for a way to launch a widget from Termux. I was not able to launch apps with the instructions above either. But anyway it's the launching of wiidgets that I'm after.

@bitcoinmeetups bitcoinmeetups changed the title How can I launch an Android shortcut from within Termux? How can I launch an Android widget from within Termux? Dec 28, 2019
@SDRausty

This comment was marked as spam.

@ghost
Copy link

ghost commented Dec 28, 2019

@bitcoinmeetups What you are looking for is the calling specific intents with specified arguments. You can't call widget directly but only what is behind it.

Example for launching Termux activity:

am start -n com.termux/.app.TermuxActivity

- note that Termux cannot have more than one activity launched at the time, existing one will be brought to the front due to configuration in AndroidManifest.xml (single task mode).

Widgets are not exception and their action can be called through argument too. But this is more complicated and there no universal way how to do that.

Example for calling scripts through Termux:Widget:

  1. Obtain the token from shared preferences. Should be possible from Termux but since I use debug versions of applications I used ADB:
herolte:/ $ run-as com.termux.widget                                                                                                                                                                              
herolte:/data/data/com.termux.widget $ cat shared_prefs/token.xml                                                                                                                                                 
<?xml version='1.0' encoding='utf-8' standalone='yes' ?>
<map>
    <string name="token">c27d1264-b1d6-48d7-980f-58cbc3e964fe</string>
</map>
  1. Get the necessary arguments for intent. In my case:
  • Activity name: com.termux.widget/.TermuxLaunchShortcutActivity
  • Script name: /data/data/com.termux/files/usr/bin/login (yes, you can execute programs outside of shortcuts with Termux:Widget).
  • Token string name: com.termux.shortcut.token
  • Token string value: c27d1264-b1d6-48d7-980f-58cbc3e964fe
  1. Execute intent with activity manager:
am start -n com.termux.widget/.TermuxLaunchShortcutActivity -d file://com.termux.widget/data/data/com.termux/files/usr/bin/login --es com.termux.shortcut.token c27d1264-b1d6-48d7-980f-58cbc3e964fe

- launches a new login shell session due to called script login, but you can put anything other here.

@ghost ghost closed this as completed Dec 28, 2019
@SDRausty

This comment has been minimized.

@SDRausty

This comment has been minimized.

@ghost
Copy link

ghost commented Dec 28, 2019

does this imply Termux app should be rebuild?

No, single task mode is intentional.

There no reason for having multiple activities. You also won't be able to start activity anyway if it is already running at the front.

Instead of

Warning: Activity not started, intent has been delivered to currently running top-most instance.

you will just get

Warning: Activity not started, its current task has been brought to the front

@SDRausty

This comment has been minimized.

@SDRausty

This comment was marked as spam.

@ghost ghost locked and limited conversation to collaborators Oct 17, 2021
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants