从SL4A脚本启动android应用程序?

2024-06-25 06:20:25 发布

您现在位置:Python中文网/ 问答频道 /正文

我在/sdcard/sl4a/scripts/twitter.py中有以下内容

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

如果我在控制台或后台运行它,它会立即以代码1退出,并且日志文件是空的。

如果有其他方法可以从某种脚本启动应用程序,我愿意接受建议。我知道Tasker,但我宁愿写文本脚本,也不愿使用向导。


Tags: 文件代码pyimport脚本comscriptstwitter
1条回答
网友
1楼 · 发布于 2024-06-25 06:20:25

您可以使用startActivity来实现:

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

请参见语法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)

相关问题 更多 >