Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Launch android app from SL4A script?

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.

like image 594
Nate Parsons Avatar asked Oct 04 '12 22:10

Nate Parsons


1 Answers

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)
like image 103
Taifun Avatar answered Sep 22 '22 01:09

Taifun