6

I have the following in /sdcard/sl4a/scripts/twitter.py

import android
droid = android.Android()
droid.launch('com.twitter.android')

And if I run it in the console or the background, it immediately exits with code 1, and the log file is empty.

If there are other ways to launch applications from some sort of script, I'm open to suggestions. I know of Tasker, but I'd rather write text scripts than use a wizard.

Nate Parsons
  • 14,431
  • 13
  • 51
  • 67
  • Of course, as soon as I ask this, I try something else that works. I can call Javascript files from Tasker, and it provides a loadApp() function that "just works". Leaving this open JIC – Nate Parsons Oct 04 '12 at 23:14
  • in case you are satisfied with the answer, please mark it as answered. Thank you. – Taifun Oct 29 '12 at 20:45

1 Answers1

9

you can use startActivity for that:

import android
droid = android.Android()
droid.startActivity('android.intent.action.MAIN', 
                    None, None, None, False, 
                    'com.twitter.android', 
                    'com.twitter.android.StartActivity'
                   )

see the syntax in the API Reference:

startActivity(
   String action,
   String uri[optional],
   String type[optional]: MIME type/subtype of the URI,
   JSONObject extras[optional]: a Map of extras to add to the Intent,
   Boolean wait[optional]: block until the user exits the started activity,
   String packagename[optional]: name of package. If used, requires classname to be useful,
   String classname[optional]: name of class. If used, requires packagename to be useful)
Taifun
  • 6,165
  • 17
  • 60
  • 188
  • What if I wanted to open -for example- a particular hashtag in twitter? or instead of twitter open a video in a video player app? – aesede Oct 30 '14 at 14:54
  • 1. I don't think you can do that, 2. try this: `droid.startActivity('android.intent.action.VIEW', 'vnd.youtube:3nH_T9fLd_Q', None, None, False, None, None)` – Taifun Oct 30 '14 at 15:47
  • Alright, that's nice, your example worked with youtube. But how do you get this part: `'vnd.youtube:vid_ID'`? where is it documented? I had hard times trying to find this kind of info. I'd like to do somehting similiar with VLC for Android, or maybe MX Player. Thanks! – aesede Oct 30 '14 at 18:14
  • 1
    I don't know where it is documented, I just copied it from [here](https://puravidaapps.com/snippets.php#2youtube)... just ask a new question... – Taifun Oct 30 '14 at 21:11