http://android-scripting.googlecode.com/hg/python/ase/android.py

拷贝到/Python27/Lib/site-packages这个目录下

Code:

 # Copyright (C)  Google Inc.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may not
# use this file except in compliance with the License. You may obtain a copy of
# the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations under
# the License. __author__ = 'Damon Kohler <damonkohler@gmail.com>' import collections
import json
import os
import socket
import sys PORT = os.environ.get('AP_PORT')
HOST = os.environ.get('AP_HOST')
HANDSHAKE = os.environ.get('AP_HANDSHAKE')
Result = collections.namedtuple('Result', 'id,result,error') class Android(object): def __init__(self, addr=None):
if addr is None:
addr = HOST, PORT
self.conn = socket.create_connection(addr)
self.client = self.conn.makefile()
self.id =
if HANDSHAKE is not None:
self._authenticate(HANDSHAKE) def _rpc(self, method, *args):
data = {'id': self.id,
'method': method,
'params': args}
request = json.dumps(data)
self.client.write(request+'\n')
self.client.flush()
response = self.client.readline()
self.id +=
result = json.loads(response)
if result['error'] is not None:
print result['error']
# namedtuple doesn't work with unicode keys.
return Result(id=result['id'], result=result['result'],
error=result['error'], ) def __getattr__(self, name):
def rpc_call(*args):
return self._rpc(name, *args)
return rpc_call

EG.

 import android
app = android.Android(('192.168.1.100',))
msg = "Hello world! Remote debug."
app.makeToast(msg)

Result(id=0, result=None, error=None)

 #导入Android的API模块
import android
#获得操作对象
droid = android.Android(('192.168.1.100', ))
#运行扫描程序,返回一个元组
code = droid.scanBarcode()
#从扫描程序返回的元组中取得isbn编号
isbn = code[]['extras']['SCAN_RESULT']
#构造查询书籍的Url
url = 'http://book.douban.com/subject_search?search_text=%s&cat=1001' % isbn
#打开浏览器,传入构造好的Url,返回查找结果
droid.startActivity('android.intent.action.VIEW',url)

最新文章

  1. 2.简单的Code First例子(EF Code-First系列)
  2. DNS弹窗广告遭遇
  3. .NET Nancy 详解(一) 初识
  4. java.util.NoSuchElementException解决办法
  5. 记录Hibernate的缓存知识
  6. 信息安全系统设计基础实验五:简单嵌入式 WEB 服务器实验 (20135229,20135234)
  7. jQuery之$(&#39;#id&#39;)和$(&#39;#&#39;+id)
  8. java 哪些情况下会使对象锁释放
  9. 实现C#给系统其他窗口输入的思路
  10. PV,UV,IP
  11. Scala学习1
  12. IC封装图片认识(二):SOP&amp;SOJ
  13. Ubuntu 如何重新安裝 Unity ?
  14. Java跨域问题的处理详解
  15. passat product list
  16. Shiro在SSM框架中的应用
  17. CCF CSP 201809-1 卖菜
  18. java 爬取 国税局 省市区级联关系
  19. java instanceof和isInstance的关系 精析
  20. 一步一步创建JAVA线程

热门文章

  1. datePicker 及 timePicker Diolage弹出对话框式 比较好看的 监听事件
  2. go变量和数据类型
  3. Mysql索引类型分析
  4. jenkins 批量修改svn 地址
  5. 特征工程之分箱--Best-KS分箱
  6. Hadoop-No.4之列式存储格式
  7. 2019CCPC秦皇岛(重现赛)-D
  8. Flyway详解以及Springboot集成Flyway(转)
  9. jenkins 中MultiJob Phase的使用,简单的pipeline可以用这个写
  10. 题解 【HEOI2016】tree树