【问题标题】:Is it possible to store SL4A scripts in a local db and run them from within a java Activity.class?是否可以将 SL4A 脚本存储在本地数据库中并从 java Activity.class 中运行它们?
【发布时间】:2011-11-27 06:29:54
【问题描述】:

我正在玩弄一个想法,其中我将 SL4A 代码脚本 sn-ps 存储在“常规”java Android 应用程序的本地数据库中。这个想法是在运行时从 Activity 类中检索这些代码 sn-ps 并执行它们。

尽管我使用了最好的 google-fu,但我还是找不到任何示例,这让我觉得这是一个不好的迹象。有很多关于如何运行 SL4A 脚本的示例,但似乎没有一个示例显示如何将脚本检索为字符串(或流)对象,然后从 Activity 中执行脚本。

我确实找到了一个接近我想要的示例,但它似乎没有提供执行多行脚本的能力,并且需要 root 访问权限。

【问题讨论】:

    标签: android python database sl4a


    【解决方案1】:

    您可以从数据库中检索脚本内容,然后将其写入文件,最后调用 SL4A 来运行它吗?一个虚构的 / Python-y 语言的例子:

    // get script
    script = db.fetchScript(ID)
    // write script to file
    path = "/mnt/sdcard/myapp/scripts/temp.py"
    file = open(path,Mode.WRITE)
    file.write(script)
    file.close()
    // execute
    intent = makeIntent(...)
    startActivity(intent)
    

    祝你好运!

    【讨论】:

      猜你喜欢
      • 2018-06-15
      • 2012-08-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多