- 浏览: 1065493 次
- 性别:
- 来自: 南昌
文章分类
- 全部博客 (276)
- 生活 (1)
- 代码之美 (22)
- Media (7)
- Android Widget (3)
- Android Intent (1)
- Android Activity (4)
- UI event handle--UI事件处理机制 (2)
- Java基础知识 (12)
- android Databases (5)
- Android 系统知识 (70)
- 平常遇到的问题与解决方法 (38)
- Android TextView/EditView (2)
- Thinking Java (1)
- android webkit (6)
- JSON (1)
- XML (4)
- HTTP (1)
- Google Weather API (1)
- android 2.3 NFC (10)
- android app (20)
- android framework (7)
- C++ (2)
- android System (5)
- Pthread (1)
- Wifi (8)
- Unix/Linux C (8)
- Android 4.0 (1)
- Mail (1)
- Smack 源码学习 (4)
- iOS (4)
- Android (1)
- git (1)
- Gallery3d (2)
- React-Natice (1)
最新评论
-
dd18349182956:
你是用的smack哪个版本?我用的smack4.1.3和sma ...
关于socket长连接的心跳包 -
xukaiyin:
全英文
getApplicationContext()与this,getBaseContext() -
裂风矢:
...
<category android:name="android.intent.category.DEFAULT" /> 惹的祸 -
xanthodont:
mark一下
XMPP——Smack -
Evilover3:
mark一下,学习了
XMPP——Smack
转自:http://code.google.com/p/android-scripting/wiki/RemoteControl
ntroduction
Sometimes it's nice to be able to write scripts on your computer and run them on the phone. This is possible using SL4A's "server" support.
First, start an SL4A server from the Interpreter Manager. (From the SL4A frontpage, press Menu, then Interpreters, then Menu, then Start Server). You can either start a public or a private server (recommended).
If you start a public server, anyone that can reach your device's IP address can control your phone. Because of this, we recommend that you start a private server instead. However, to use a private server you will need to install the Android SDK and add the adb utility to your path.
When you use a private server and set up port forwarding and environment variables as described below, then you will be able to run scripts on your computer that should also work unmodified when run directly on the phone. NICE. This is not true for public servers.
To use a private server, first connect your device to your computer via USB (this is not necessary if you are using a public server).
Note the port displayed in the SL4A notification in the Android notification area,
Use adb to forward the network connection to your phone, AND
Set the AP_PORT environment variable.
Example: Suppose you've started a private server within SL4A which you've noted is listening on port 4321. You've connected the device to your computer with a USB cable, and you've verified that "USB debugging connected" shows up in the Android notification area.
You would then set up port forwarding like:
$ adb forward tcp:9999 tcp:4321
This command will forward all local traffic targeting port 9999 to the private-server port on the Android device (port 4321 in this example).
Next you must set up an environment variable (AP_PORT) that the android bindings use to find the local port. Continuing with the example above, you would do:
$ export AP_PORT=9999 # Use set AP_PORT=9999 on Windows
If you don't want to connect your device to the host over USB, you can use a public server. For public servers, you must additionally export the IP of the device. To extend the previous example, suppose your phone is connected over wifi on your home network and has an IP address of 192.168.0.100. You would now need to do:
$ export AP_PORT=4321 # Use set AP_PORT=9999 on Windows
$ export AP_HOST=192.168.0.100 # Use set AP_HOST=192.168.0.100 on Windows
Now you can execute Python or Lua on your PC, import the android package or module for the language, and interact with the AndroidProxy on the phone.
For Example
For our example, let's use Python.
First, make sure that you have Python 2.6 installed on your computer (this matches the Python version that SL4A uses on the phone).
Then, make sure you have the SL4A's android.py module in your Python path (i.e. in site-packages or the current directory). android.py is the only extra file you need; you don't need to do any sort of extensive SL4A install on your computer.
Then, connect your Android device via USB, start a private server, and set up adb port forwarding and the AP_PORT environment variable as described above.
Now you can have some fun!
$ python
Python 2.6
Type "help", "copyright", "credits" or "license" for more information.
>>> import android # The SL4A android.py module should be on your sys.path.
>>> droid = android.Android() # Or android.Android(('192.168.1.101', 6789)) for a public server, where 192.168.1.101 is the public server's IP, and 6789 is its port.
>>> droid.makeToast("Hello from my computer!")
Rhino Example
A HOWTO for Rhino.
Copying Scripts to Your Phone
Once you're satisfied, you can copy script to your phone:
$ adb push my_script.py /sdcard/sl4a/scripts
Now you can execute or continue to edit the script on your phone.
Remotely Starting SL4A
It is possible to launch scripts on your phone via the adb shell:
Launch a script in the background.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_BACKGROUND_SCRIPT -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher -e com.googlecode.android_scripting.extra.SCRIPT_PATH /sdcard/sl4a/scripts/test.py
Launch a script in a terminal.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_FOREGROUND_SCRIPT -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher -e com.googlecode.android_scripting.extra.SCRIPT_PATH /sdcard/sl4a/scripts/test.py
It is also possible to launch an SL4A server via the adb shell:
Start a private server.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher
Start a public server.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher --ez com.googlecode.android_scripting.extra.USE_PUBLIC_IP true
Troubleshooting
If you've mounted your SD card on your computer, the lists of scripts will appear empty in SL4A on your phone. Don't panic. As soon as you unmount the SD card on your computer, SL4A will display the list of scripts again.
If you try to set up adb port forwarding and get "no device found" errors, ensure that "USB debugging" is enabled on your phone and all proper drivers are installed on your computer. You can enable USB debugging on your phone under Settings > Applications > Development > USB debugging. In general, external scripting via private server will only work if "adb devices" shows your android device after you've connected it via USB. If "adb devices" comes up empty, Google around for tips on this problem before trying to move forward with SL4A itself.
ntroduction
Sometimes it's nice to be able to write scripts on your computer and run them on the phone. This is possible using SL4A's "server" support.
First, start an SL4A server from the Interpreter Manager. (From the SL4A frontpage, press Menu, then Interpreters, then Menu, then Start Server). You can either start a public or a private server (recommended).
If you start a public server, anyone that can reach your device's IP address can control your phone. Because of this, we recommend that you start a private server instead. However, to use a private server you will need to install the Android SDK and add the adb utility to your path.
When you use a private server and set up port forwarding and environment variables as described below, then you will be able to run scripts on your computer that should also work unmodified when run directly on the phone. NICE. This is not true for public servers.
To use a private server, first connect your device to your computer via USB (this is not necessary if you are using a public server).
Note the port displayed in the SL4A notification in the Android notification area,
Use adb to forward the network connection to your phone, AND
Set the AP_PORT environment variable.
Example: Suppose you've started a private server within SL4A which you've noted is listening on port 4321. You've connected the device to your computer with a USB cable, and you've verified that "USB debugging connected" shows up in the Android notification area.
You would then set up port forwarding like:
$ adb forward tcp:9999 tcp:4321
This command will forward all local traffic targeting port 9999 to the private-server port on the Android device (port 4321 in this example).
Next you must set up an environment variable (AP_PORT) that the android bindings use to find the local port. Continuing with the example above, you would do:
$ export AP_PORT=9999 # Use set AP_PORT=9999 on Windows
If you don't want to connect your device to the host over USB, you can use a public server. For public servers, you must additionally export the IP of the device. To extend the previous example, suppose your phone is connected over wifi on your home network and has an IP address of 192.168.0.100. You would now need to do:
$ export AP_PORT=4321 # Use set AP_PORT=9999 on Windows
$ export AP_HOST=192.168.0.100 # Use set AP_HOST=192.168.0.100 on Windows
Now you can execute Python or Lua on your PC, import the android package or module for the language, and interact with the AndroidProxy on the phone.
For Example
For our example, let's use Python.
First, make sure that you have Python 2.6 installed on your computer (this matches the Python version that SL4A uses on the phone).
Then, make sure you have the SL4A's android.py module in your Python path (i.e. in site-packages or the current directory). android.py is the only extra file you need; you don't need to do any sort of extensive SL4A install on your computer.
Then, connect your Android device via USB, start a private server, and set up adb port forwarding and the AP_PORT environment variable as described above.
Now you can have some fun!
$ python
Python 2.6
Type "help", "copyright", "credits" or "license" for more information.
>>> import android # The SL4A android.py module should be on your sys.path.
>>> droid = android.Android() # Or android.Android(('192.168.1.101', 6789)) for a public server, where 192.168.1.101 is the public server's IP, and 6789 is its port.
>>> droid.makeToast("Hello from my computer!")
Rhino Example
A HOWTO for Rhino.
Copying Scripts to Your Phone
Once you're satisfied, you can copy script to your phone:
$ adb push my_script.py /sdcard/sl4a/scripts
Now you can execute or continue to edit the script on your phone.
Remotely Starting SL4A
It is possible to launch scripts on your phone via the adb shell:
Launch a script in the background.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_BACKGROUND_SCRIPT -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher -e com.googlecode.android_scripting.extra.SCRIPT_PATH /sdcard/sl4a/scripts/test.py
Launch a script in a terminal.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_FOREGROUND_SCRIPT -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher -e com.googlecode.android_scripting.extra.SCRIPT_PATH /sdcard/sl4a/scripts/test.py
It is also possible to launch an SL4A server via the adb shell:
Start a private server.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher
Start a public server.
$ am start -a com.googlecode.android_scripting.action.LAUNCH_SERVER -n com.googlecode.android_scripting/.activity.ScriptingLayerServiceLauncher --ez com.googlecode.android_scripting.extra.USE_PUBLIC_IP true
Troubleshooting
If you've mounted your SD card on your computer, the lists of scripts will appear empty in SL4A on your phone. Don't panic. As soon as you unmount the SD card on your computer, SL4A will display the list of scripts again.
If you try to set up adb port forwarding and get "no device found" errors, ensure that "USB debugging" is enabled on your phone and all proper drivers are installed on your computer. You can enable USB debugging on your phone under Settings > Applications > Development > USB debugging. In general, external scripting via private server will only work if "adb devices" shows your android device after you've connected it via USB. If "adb devices" comes up empty, Google around for tips on this problem before trying to move forward with SL4A itself.
发表评论
-
打印调用堆栈
2019-11-15 15:48 486平常我们遇到不清楚代码逻辑的,可以通过打印调用堆栈来理清楚,如 ... -
你知道Log.isLoggable
2018-11-23 14:15 964我们可以通过Log.isLoggable来动态开关log的输出 ... -
android:allowUndo
2018-04-25 16:51 786Android 在Android 23增加了UndoManag ... -
mipmap-xxx
2015-12-10 11:35 1107最近在看AOSP,发现mipmaps, 百度 了一下,发现有各 ... -
《Android.Programming.Pushing.the.Limits].Erik.Hellman》记录1
2015-10-29 10:56 580最近在看《Android.Programming.Pushin ... -
System.currentTimeMillis() uptimeMillis elapsedRealtime 区别
2015-10-28 20:02 1317转自http://blog.csdn.net/wutianyi ... -
GPS的开关设置
2015-09-29 18:36 2036//modify by hyxu 2015-9-30 to s ... -
DialogFragment
2015-09-25 13:56 1051public class YesNoDialog extend ... -
ANDROID L——RecyclerView,CardView导入和使用
2015-07-23 09:51 959转自http://blog.csdn.net/a3969019 ... -
IntentService 和ResultReceiver
2015-07-22 20:00 814转自[url] http://javatechig.com/a ... -
Android media媒体库分析之:分类别统计媒体文件大小
2015-07-21 20:07 552转自http://www.linuxidc.com/Linux ... -
java.lang.IllegalArgumentException: Service Intent must be explicit
2015-07-21 20:03 1306转自:http://www.2cto.com/kf/20150 ... -
Context 和Application Context
2015-02-11 15:14 883http://possiblemobile.com/2013/ ... -
ContentProviderOperation.Builder 中withValue和withValueBackReference的区别
2015-02-10 14:01 2202关于ContentProviderOperation.Buil ... -
AndroidManifest.xml的Service元素 android:process设置
2013-05-30 17:02 11488转自:http://galin.blog.sohu ... -
android中打包含有Activity以及资源文件的jar包在工程中调用
2013-05-28 15:00 1322转自:http://www.cnblogs.com/vaiya ... -
Android杂谈--内存泄露(1)--contentView缓存使用与ListView优化
2012-11-01 09:29 2836转自:http://www.cnblogs.com/louli ... -
Handler+ExecutorService(线程池)+MessageQueue模式+缓存模式
2012-10-31 14:32 1891转自:http://www.eoeandroid.com/th ... -
Animation
2012-10-30 13:41 1136转自:http://hi.baidu.com/wendaoer ... -
Android onTouchEvent和onInterceptTouchEvent
2012-10-24 15:05 1290ViewGroup里的onInterceptTouchEven ...
相关推荐
sl4a for android script 开发
SL4A,全称为Scripting Layer for Android,是一款强大的Android平台上的脚本开发工具,它允许用户使用多种脚本语言(如Python、JavaScript等)来控制Android设备,进行自动化任务和交互。标题中的"SL4A-of-Python_...
PythonForAndroid-r7b1+sl4a.zip这个压缩包文件是关于在Android平台上运行Python环境的工具集合,其中包含了PythonForAndroid和SL4A(Scripting Layer for Android)两个重要组件。这两个工具使得开发者可以在...
Google官方博客介绍了Android Scripting Environment(ASE、SL4A),将脚本语言带入Android,允许用户编辑和执行脚本,直接在Android设备上运行交互式解释器。脚本将能大幅度简化任务界面,用户能在交互式终端中使用...
SL4A,全称为Scripting Layer for Android,是一款强大的Android平台上的自动化工具,它允许用户通过编程语言(如Python)来控制和与Android设备交互。这个压缩包包含了SL4A的Python API的中英文参考文档,是开发者...
SL4A,全称为"Scripting Layer for Android",是一个为Android平台设计的开源项目,旨在让开发者和用户能够通过脚本语言控制Android设备。SL4A提供了丰富的API,允许编写简单的脚本来实现对Android设备的各种操作,...
《Apress.Pro.Android.Python.with.SL4A.Jul.2011》是一部关于在Android平台上使用Python编程的专业书籍,结合了SL4A(Scripting Layer for Android)这一强大的工具,让开发者能够利用Python语言的简洁性和强大功能...
SL4A,全称为"Scripting Layer for Android",是一个为Android平台设计的开源项目,旨在让开发者和普通用户能够通过脚本语言控制和自动化Android设备。SL4A提供了丰富的API,可以调用Android系统的各种功能,如...
SL4A(Scripting Layer for Android)是为Android平台设计的一套脚本层,它允许开发者使用各种脚本语言,比如Python、Ruby、Lua等,来编写Android应用程序而不需要使用Java。SL4A的主要目标是提供一种简便快速的方式...
PythonForAndroid、SL4A两个安装包,安装后可在安卓平台上运行python
《Pro.Android.Python.with.SL4A(第1版)》是一本专注于使用Python语言以及少量JavaScript在Android平台上开发实际应用的书籍。本书的核心在于介绍Scripting Layer for Android(SL4A)项目,一个旨在满足特定需求的...
SL4A,全称为"Scripting Layer for Android",是一个为Android平台设计的脚本环境,它允许用户通过各种编程语言编写控制Android设备的应用程序。SL4A的主要目的是简化Android应用的开发,使得非专业程序员也能创建...
Scripting Layer for Android (SL4A) brings scripting languages to Android by allowing you to edit and execute scripts and interactive interpreters directly on the Android device. These scripts have ...
SL4A开发APK文档集合 pro-android-python-with-sl4a.pdf PythonForAndroid_r4.apk sl4a_r6.apk [android.开发书籍].Practical.Android.Projects.pdf
android脚本环境的APK应用,目前已支持Python,Lua, BeanShell, Perl等语言。
SL4A,全称为Scripting Layer for Android,是一款在Android平台上运行脚本语言的框架,旨在让开发者能够方便地在Android设备上编写和执行各种脚本。标题中的"sl4a-r3.rar"指的是SL4A的第三版(r3)的压缩包文件,这...
PythonForAndroid、SL4A两个安装包,安装后可在安卓平台上运行python。
Pro_Android_Scripting_with_SL4A__Writing_Android_Native_Apps_Using_Python__Lua__and_Beanshell.mobi
sl4a_r6 供自己学习,也分享出来给大家使用,需要的话可以下载,有什么问题可以留言
SL4A,全称为"Scripting Layer for Android",是一个为Android平台设计的脚本环境,它允许用户通过各种编程语言来控制和自动化Android设备。SL4A的主要目的是简化Android设备的编程,使得非专业开发者也能轻松进行...