【问题标题】:Is there a way to run SL4A script from a directory elsewhere?有没有办法从其他地方的目录运行 SL4A 脚本?
【发布时间】:2011-12-31 13:37:25
【问题描述】:

sl4a 的所有脚本都在 /sdcard/sl4a/scripts 下

是否可以运行其他地方的脚本:

例如来自 /sdcard/dropbox/pyscripts [眨眼]

【问题讨论】:

    标签: android sl4a


    【解决方案1】:

    这有点老了,但我来这里是为了寻找这个问题的答案,我找到了一个,所以我想我应该与其他人分享它。谷歌搜索与我相同的东西。

    当您发出 Android Intent 以在 SL4A 中运行脚本时,您可以指定文件系统上的任何脚本。你可以编写一个脚本来发出这个意图,(或者一个应用程序,如果你喜欢的话)。下面是一个 Python 示例:

    import android
    
    droid = android.Android()
    
    activity = 'com.googlecode.android_scripting.action.LAUNCH_BACKGROUND_SCRIPT'
    extras = {}
    extras['com.googlecode.android_scripting.extra.SCRIPT_PATH'] = '/any/script/you/like.py'
    
    packagename =  'com.googlecode.android_scripting'
    classname = 'com.googlecode.android_scripting.activity.ScriptingLayerServiceLauncher'
    
    intent = droid.makeIntent(activity, None, None, extras, None, packagename, classname).result
    
    droid.startActivityIntent(intent)
    

    我已考虑到这一点,因此(我希望)更容易看到发生了什么。如果您从脚本调用 getIntent(),它将向您显示调用它的意图的剖析。我就是这么想的。

    【讨论】:

    • 谢谢。太棒了。它应该被更多地投票,因为它仍然很难找到。
    【解决方案2】:

    我认为目前的答案是否定的。

    该应用没有设置该路径的选项。我唯一的另一个想法是创建一个从保管箱文件夹到脚本目录的符号链接。但这也有一些主要问题,最大的问题是大多数 SD 卡都是用 FAT32 格式化的,它根本不支持符号链接。如果您有不同的文件系统,则可以尝试该路径。不确定是否需要root - 我想在sdcard上写应该不需要。 也不确定应用程序是否正确处理链接,但理论上整个链接应该对其不可见并作为普通文件夹处理。

    【讨论】:

    • 这个答案并不正确。请参阅下面 crocodilewings 的回答。
    【解决方案3】:

    回答一个老问题.. 但我找到了一种方法,使用 Dropsync(免费应用程序)可以将 SD 卡上的任何文件夹与特定的 DropBox 文件夹同步。 它可以双向同步,但也有许多其他同步选项。

    拖放同步: https://play.google.com/store/apps/details?id=com.ttxapps.dropsync&hl=en

    【讨论】:

      【解决方案4】:

      试试 Touchqode 应用。它可以执行 sl4a 脚本。

      【讨论】:

        【解决方案5】:
        <intent-filter>
                         <action android:name="android.intent.action.VIEW" />
                         <category android:name="android.intent.category.DEFAULT" />
                         <data android:scheme="file" />
                         <data android:host="*" />
                         <data android:pathPattern=".*\\.py"
                             android:mimeType="*/*" />
        </intent-filter>
        

        将其添加到主活动意图过滤器下的应用清单

                String path = getIntent().getDataString();
                if(path!=null){         //this happens if you open the app without clicking on any .py file
                    path=path.substring(7);
                    Intent intent=new Intent();                     
                    intent.setComponent(new ComponentName("com.googlecode.android_scripting","com.googlecode.android_scripting.activity.ScriptingLayerServiceLauncher"));   
                    intent.putExtra("com.googlecode.android_scripting.extra.SCRIPT_PATH",path);
                    intent.setAction("com.googlecode.android_scripting.action.LAUNCH_FOREGROUND_SCRIPT");
                    startActivity(intent);
                    System.exit(0);
        
               }
        

        将此代码添加到主活动

        现在你有了一个闪亮的应用程序,只要你点击任何扩展名为 .py 的文件,它就会启动 要使用更多脚本类型,请添加更多 pathPatterns。此外,您现在可以编写自己的应用程序来编辑 .py 文件/搜索任何位置的所有脚本,然后在 sl4a 中运行它们。 Play 商店中还有一个名为 sl4a 脚本启动器的应用

        【讨论】:

          猜你喜欢
          • 2021-12-24
          • 1970-01-01
          • 2019-11-18
          • 2016-03-18
          • 1970-01-01
          • 2022-01-13
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多