James Ing Wei Tang - Honey, There Is a Python in My Android Phone!

Опубликовано: 11 Октябрь 2020
на канале: EuroPython Conference
1,046
21

"Honey, There Is a Python in My Android Phone!
EuroPython 2020 - Talk - 2020-07-23 - Ni
Online

By James Ing Wei Tang

This is a small code snippet that I have written in Python for the POC of getting the GPS coordinate from android phone:

import androidhelper
import json
import time
from bottle import Bottle, run, response, request

app = Bottle()
droid = androidhelper.Android()

@app.route(""/location"")
def get_location():

precodedroid.startLocating()
droid.eventWaitFor('location', 12500)

time.sleep(0.1)

current_location = droid.readLocation().result

if not current_location:
current_location = droid.getLastKnownLocation().result

droid.stopLocating()
response.content_type = ""application/json""

return json.dumps(

""result"": current_location
, indent=4
)
/code/pre

This project was initiated during my Christmas vacation, inspired by Android Barcode Scanner as I was looking on the solution that I could catalogue my books by scanning the ISBN using android phone.

This quick solution did save me enormous amount of time in cataloguing my books. Intriguing by the design of APIs that can interact with android intents, I decided to dig further to understand how the APIs works. In concept, there is an RPC call between android app and python interpreter within the app that acts as a bridge, which allows python APIs to trigger Android intents, upon calling related APIs. For example, using the code snippet above, when Python GPS API is executed, the API will send request to Android GPS intent via the RPC call. Once Android intent receives the request, it will grab the GPS data, and passes the GPS data back to Python GPS API through the same channel.

Reference:
python-for-android
Qpython
Android Barcode Scanner



License: This video is licensed under the CC BY-NC-SA 3.0 license: https://creativecommons.org/licenses/...
Please see our speaker release agreement for details: https://ep2020.europython.eu/events/s...

"


Смотрите видео James Ing Wei Tang - Honey, There Is a Python in My Android Phone! онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь EuroPython Conference 11 Октябрь 2020, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 1,046 раз и оно понравилось 21 людям.