Is there a way to run SL4A script from a directory elsewhere?

半城伤御伤魂 提交于 2019-12-05 14:00:09

I think the answer is no at this moment in time.

The app does not have a option to set that path. The only other idea I had was to create a symbolic link from the dropbox folder to the scripts dir. But this has a few major problems too, the biggest beeing that most SD-cards are formatted with FAT32, which simply does not support symbolic links. If you have a different filesystem, you can try that path though. Not sure if root is required - I'd imagine that writing on the sdcard should not require that. Also not sure if the app handles a link correctly, but in theory the whole link should be invisible to it and be handled as a normal folder.

This is a bit old, but I came here looking for an answer to this question, and I found one, so I figured I should share it with anyone else Googling the same stuff as me.

When you issue an Android intent to run a script in SL4A, you can specify any script on the file system. You can write a script to issue this intent, (or an app, if you felt like it). Here's an example in 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)

I've factored this so it's easier (I hope) to see what's going on. If you call getIntent() from a script, it will show you the anatomy of the intent that calls it. That's how I figured it out.

Replying to an old question.. But I found a way to do this by using Dropsync (free app) which can sync any folder on your SD card with a particular DropBox folder. It can sync both ways, but has many other syncing options too.

Dropsync: https://play.google.com/store/apps/details?id=com.ttxapps.dropsync&hl=en

mik-d

Try the Touchqode app. It can execute sl4a scripts.

<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>

Add that to App manifest under mainactivity 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);

       }

Add this code to Main Activity

Now you have a shiny app that will be launched whenever you click on any file with extension .py To use more script types add more pathPatterns. Additionally you can now write your own app to edit .py files/ search all scripts in any location and all and then run them in sl4a. There is also an app called sl4a script launcher in play store

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!