
Sicuramente questo rappresenta un grosso vantaggio, poichè sarà possibile creare nuovi script utilizzanto un’ interfaccia semplificata direttamente eseguita sul terminale Android.
Queste sono le API a cui possiamo accedere dall’ interfaccia di scripting:
- Handle intents
- Start activities
- Make phone calls
- Send text messages
- Scanbar codes
- Poll location and sensor data
- Usetext-to-speech
- Altre…
Gli script possono essere eseguiti direttamente dal terminale o in locale. Sono inoltre supportati i seguenti linguaggi di programmazione: Python, Lua e BeanShell è previsto l’ inserimento del supporto Ruby e JavaScript.
Qui in basso, un esempio di script scritto in Lua:
[code]
–Placing the phone face down will disable the ringer. Turning it face up again will enable
–the ringer.
require “android”
android.startSensing()
android.sleep(1) –Give the sensors a moment to come online.
silent = false
while true do
s = android.readSensors()
facedown = s.result and s.result.zforce and s.result.zforce > 9
if facedown and not silent then
android.vibrate() –A short vibration to indicate we are in silent mode.
android.setRingerSilent(true)
silent = true
elseif not facedown and silent then
android.setRingerSilent(false)
silent = false
end
android.sleep(1)
end
[/code]
Eccone un altro scritto in Python:
[code]
“””Say chat messages aloud as they are received.”””
import android
import xmpp
_SERVER = ‘talk.google.com’, 5223
class SayChat(object):
def __init__(self):
self.droid = android.Android()
username = self.droid.getInput(‘Username’)[‘result’]
password = self.droid.getInput(‘Password’)[‘result’]
jid = xmpp.protocol.JID(username)
self.client = xmpp.Client(jid.getDomain(), debug=[])
self.client.connect(server=_SERVER)
self.client.RegisterHandler(‘message’, self.message_cb)
if not self.client:
print ‘Connection failed!’
return
auth = self.client.auth(jid.getNode(), password, ‘botty’)
if not auth:
print ‘Authentication failed!’
return
self.client.sendInitPresence()
def message_cb(self, session, message):
jid = xmpp.protocol.JID(message.getFrom())
username = jid.getNode()
text = message.getBody()
self.droid.speak(‘%s says %s’ % (username, text))
def run(self):
try:
while True:
self.client.Process(1)
except KeyboardInterrupt:
pass
saychat = SayChat()
saychat.run()
[/code]




