Chinaunix首页 | 论坛 | 博客
  • 博客访问: 9393457
  • 博文数量: 1747
  • 博客积分: 12961
  • 博客等级: 上将
  • 技术积分: 20060
  • 用 户 组: 普通用户
  • 注册时间: 2009-01-09 11:25
个人简介

偷得浮生半桶水(半日闲), 好记性不如抄下来(烂笔头). 信息爆炸的时代, 学习是一项持续的工作.

文章分类

全部博文(1747)

文章存档

2024年(23)

2023年(26)

2022年(112)

2021年(217)

2020年(157)

2019年(192)

2018年(81)

2017年(78)

2016年(70)

2015年(52)

2014年(40)

2013年(51)

2012年(85)

2011年(45)

2010年(231)

2009年(287)

分类: LINUX

2009-06-10 09:09:48

The Android Scripting Environment (ASE) 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:

  • Handle intents
  • Start activities
  • Make phone calls
  • Send text messages
  • Scan
  • Poll location and sensor data
  • Use
  • And

Scripts can be run interactively in a terminal, started as a long running service, or started via . Python, Lua and BeanShell are currently supported, and we're planning to add Ruby and JavaScript support, as well.

You may ask, why write scripts instead of real Android applications? Admittedly, Android's development environment makes life pretty easy, but you're tied to a computer to do your work. ASE lets you develop on the device itself using high-level scripting languages to try out your idea now, in the situation where you need it, quickly. Have a look at this example Lua script to see for yourself:

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

Here's another useful script. This time, in Python.

"""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()
 
具体的wiki 和 apk包 参见 
阅读(1144) | 评论(0) | 转发(0) |
0

上一篇:使用udev添加设备

下一篇:Android RIL

给主人留下些什么吧!~~