2. Outline Introduction Usage Examples
.. ... ...
.... .
......... ...
....
1 Outline
2 Introduction
Overview of the SL4A
3 Usage
Install
Architecture
usage
Sharing Scripts
4 Examples
download
httpserver
text to speech
. . . . . .
louieli yafeilee@qq.com
INTRODUCTION TO SL4A
3. Outline Introduction Usage Examples
.. ... ...
.... .
......... ...
....
Overview of the SL4A
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
access to many of the APIs available to full-fledged Android
applications, but with a greatly simplified interface that makes it
easy to get things done.
. . . . . .
louieli yafeilee@qq.com
INTRODUCTION TO SL4A
4. Outline Introduction Usage Examples
.. ... ...
.... .
......... ...
....
Overview of the SL4A
. . . . . .
louieli yafeilee@qq.com
INTRODUCTION TO SL4A
11. Outline Introduction Usage Examples
.. ... ...
.... .
......... ...
....
Architecture
All SL4A API calls return an object with three fields:
id: a strictly increasing, numeric id associated with the API
call.
result: the return value of the API call, or null if there is no
return value.
error: a description of any error that occurred or null if no
error occurred.
. . . . . .
louieli yafeilee@qq.com
INTRODUCTION TO SL4A
12. Outline Introduction Usage Examples
.. ... ...
.... .
......... ...
....
usage
Python
1 import android
2
3 droid = android.Android()
4 name = droid.getInput(”Hello!”, ”What is your name?”)
5 print name # name is a namedtuple
6 droid.makeToast(”Hello, %s” % name.result)
. . . . . .
louieli yafeilee@qq.com
INTRODUCTION TO SL4A
21. Outline Introduction Usage Examples
.. ... ...
.... .
......... ...
....
Sharing Scripts
QR Code
1 Open http://zxing.appspot.com/generator/
2 Open the Contents drop down and choose Text.
3 On the first line of the Text Content, enter the name of the
script.
4 Below that, paste the script content.
5 Open the Size drop down and choose L.
6 Click Generate.
7 Embed or share the resulting barcode image with your friends.
. . . . . .
louieli yafeilee@qq.com
INTRODUCTION TO SL4A
23. Outline Introduction Usage Examples
.. ... ...
.... .
......... ...
....
Sharing Scripts
QR Code
To download the script to your phone:
1 Launch SL4A or return the scripts list.
2 Press the Menu button.
3 Tap Add.
4 Tap Scan Barcode.
5 Scan the barcode and SL4A will add the script to your list.
A QR code can encode 4,296 characters of content. So, this is
only effective for small scripts.
. . . . . .
louieli yafeilee@qq.com
INTRODUCTION TO SL4A