Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save riverfor/b415cd47399180ee04d19eecbf824643 to your computer and use it in GitHub Desktop.

Select an option

Save riverfor/b415cd47399180ee04d19eecbf824643 to your computer and use it in GitHub Desktop.
from androidhelper import Android
import socket
from json import loads
def parseEvent(line):
out = loads(line)
out.update(loads(out["data"]))
return out
####connected via USB
droid = Android()
ACTION="android.telephony.TelephonyManager.PHONE_STATE"
droid.eventRegisterForBroadcast(ACTION, False)
####at this line, i can see my Action registred
print droid.eventGetBrodcastCategories()
p=droid.startEventDispatcher().result
####at this line, i see the Port
print(p)
s=socket.socket()
s.connect(('localhost', p))
f=s.makefile()
##Problem
###when you run this command in this line, the Console depends on
print(f.readline())
while True:
print('test')
event = parseEvent(f.readline())
print(event)
droid.log(str(event))
print("got:"+str(event))
print(droid.eventUnregisterForBroadcast(ACTION))
print(droid.eventGetBrodcastCategories())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment