Last active
August 29, 2015 14:05
-
-
Save mouuff/8544632f65fb306f2887 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
import android,time | |
droid = android.Android() | |
def getPos(waitTime=15): | |
droid.startLocating() | |
time.sleep(waitTime) | |
loc = droid.readLocation().result | |
if not loc: | |
loc = getLastKnownLocation().result | |
if loc: | |
try: | |
n = loc['gps'] | |
print "Got gps location" | |
except KeyError: | |
n = loc['network'] | |
print "Got network location" | |
droid.stopLocating() | |
return n | |
while 1: | |
time.sleep(100) | |
msgIDs = droid.smsGetMessageIds(True, 'inbox').result | |
if msgIDs: | |
for msgID in msgIDs: | |
message = droid.smsGetMessageById(msgID, ['address','body']).result | |
number = message['address'].encode('utf-8') | |
body = message['body'].encode('utf-8') | |
args = body.split() | |
if (args[0]=="getPos"): | |
try: | |
waitTime = int(args[1]) | |
except: | |
waitTime = 50 | |
n = getPos(waitTime) | |
la = n['latitude'] | |
lo = n['longitude'] | |
Address = str(la)+","+str(lo) | |
droid.smsSend(number, "Position: "+Address+" accuracy:"+str(n["accuracy"])+" meters") | |
droid.smsDeleteMessage(msgID) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment