Last active
December 30, 2015 02:59
-
-
Save importre/7766505 to your computer and use it in GitHub Desktop.
apk installer for devices connected to your machine with GUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
python %~dp0\\install_apk.py %1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
# -*- coding: utf-8 -*- | |
__author__ = 'importre' | |
__email__ = '[email protected]' | |
import re | |
import socket | |
import subprocess | |
import sys | |
from Tkinter import * | |
HOST = 'localhost' | |
PORT = 5037 | |
class PyADB(object): | |
def __init__(self): | |
subprocess.call(['adb', 'start-server',]) | |
pass | |
def __get_socket(self): | |
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) | |
try: | |
sock.connect((HOST, PORT,)) | |
except Exception as why: | |
print why | |
return None | |
return sock | |
def __send_command(self, sock, cmd): | |
cmd = '%04X%s' % (len(cmd), cmd,) | |
sock.send(cmd) | |
pass | |
def get_devices(self): | |
sock = self.__get_socket() | |
if not sock: | |
return {} | |
cmd = 'host:devices-l' | |
self.__send_command(sock, cmd) | |
response = sock.recv(4) | |
if 'OKAY' != response: | |
return {} | |
size = int(sock.recv(4), 16) | |
data = sock.recv(size) | |
ret = [] | |
lines = data.strip().split('\n') | |
for line in lines: | |
line = re.split('\s+', line.strip()) | |
obj = {'serial': line[0], 'state': line[1]} | |
for item in line[2:]: | |
if item.startswith('product:'): | |
obj['product'] = item[len('product:'):] | |
elif item.startswith('model:'): | |
obj['model'] = item[len('model:'):] | |
elif item.startswith('device:'): | |
obj['device'] = item[len('device:'):] | |
elif item.startswith('usb:'): | |
obj['usb'] = item[len('usb:'):] | |
else: | |
pass | |
ret.append(obj) | |
sock.close() | |
return ret | |
pass | |
class ApkInstaller(Frame): | |
def __init__(self, apk_path, master=None): | |
Frame.__init__(self, master, colormap='new') | |
self.pack() | |
self.apk_path = apk_path | |
self.__init_view() | |
pass | |
def __init_view(self, master=None): | |
adb = PyADB() | |
self.devices = adb.get_devices() | |
self.checked = [] | |
for idx, device in enumerate(self.devices): | |
serial = device.get('serial') | |
product = device.get('product') | |
model = device.get('model') | |
var = IntVar(); | |
var.set(1) | |
self.checked.append(var) | |
text = '%s (%s:%s)' % (model, product, serial) | |
check = Checkbutton(master, text=text, variable=var) | |
check.pack(fill=X, padx=5, pady=5) | |
separator = Frame(height=2, bd=1, relief=SUNKEN) | |
separator.pack(fill=X, padx=5, pady=5) | |
install = Button(master, text='install', command=self.__install_apk) | |
install.focus_force() | |
install.pack(fill=X, padx=5, pady=5) | |
pass | |
def __install_apk(self): | |
for idx, chk in enumerate(self.checked): | |
device = self.devices[idx] | |
serial = device.get('serial') | |
if not chk.get(): | |
continue | |
subprocess.call([ | |
'adb', '-s', serial, | |
'install', '-r', self.apk_path, | |
]) | |
pass | |
pass | |
if __name__ == '__main__': | |
if len(sys.argv) > 1 and sys.argv[1].endswith('.apk'): | |
app = ApkInstaller(apk_path=sys.argv[1]) | |
app.master.title("APK Installer") | |
app.mainloop() | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
APK installer with GUI
Install apk on your devices with GUI
How to Set
To set the default program of *.apk on Windows
install_apk.bat
.How to use
Just double-click an apk file.