Python安装远程调试Android需要的扩展脚本
2024-10-07 00:28:23
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)
最新文章
- 2.简单的Code First例子(EF Code-First系列)
- DNS弹窗广告遭遇
- .NET Nancy 详解(一) 初识
- java.util.NoSuchElementException解决办法
- 记录Hibernate的缓存知识
- 信息安全系统设计基础实验五:简单嵌入式 WEB 服务器实验 (20135229,20135234)
- jQuery之$(&#39;#id&#39;)和$(&#39;#&#39;+id)
- java 哪些情况下会使对象锁释放
- 实现C#给系统其他窗口输入的思路
- PV,UV,IP
- Scala学习1
- IC封装图片认识(二):SOP&;SOJ
- Ubuntu 如何重新安裝 Unity ?
- Java跨域问题的处理详解
- passat product list
- Shiro在SSM框架中的应用
- CCF CSP 201809-1 卖菜
- java 爬取 国税局 省市区级联关系
- java instanceof和isInstance的关系 精析
- 一步一步创建JAVA线程