Python package for Android USB host.
Please try the Android App built with usb4a on Google Play: PyTool USB Serial Free.
Please consider to support me.
Android platform related classes:
PythonActivity
Context
Intent
PendingIntent
USB related classes:
UsbConstants
UsbRequest
USBError
Helper classes:
ByteBuffer
Helper functions:
get_usb_manager
get_usb_device_list
get_usb_device
has_usb_permission
request_usb_permission
build_usb_control_request_type
arraycopy
This package can be used for implementing USB device driver for Android USB host, like USB serial port drivers.
If not in need to build a dedicated app:
It works for Android 6.0+.
Get Pydroid apps from here.
Or get the latest versions on Google Play.
In Pydroid, go to Menu->Pip.
Install usb4a.
Open example.py
and run it.
Go to Menu->Graphical program output.
Scroll to the last line, it should list all the USB devices connected to the Android phone/tablet with vendor id, vendor name, product id and product name.
If a dedicated app is needed to be built with buildozer:
It works for Android 4.0+.
In buildozer.spec add termios.so to the whitelist.
Include usb4a in requirements.
Add intent-filter.xml.
# (list) python-for-android whitelist
android.p4a_whitelist = lib-dynload/termios.so
# (list) Application requirements
# comma seperated e.g. requirements = sqlite3,kivy
requirements = kivy, pyjnius, usb4a
# (str) XML file to include as an intent filters in <activity> tag
android.manifest.intent_filters = intent-filter.xml
Build the project for the first time and it will fail with an error as expected.
buildozer android debug
In the generated .buildozer
folder find a res
folder like this one:
.buildozer/android/platform/build/dists/YOU_PROJECT_NAME/src/main/res
Create a xml
folder in res
folder.
Add device_filter.xml to this res/xml/
folder.
Find a manifest template file like this one:
.buildozer/android/platform/build/dists/YOUR_PROJECT_NAME/templates/AndroidManifest.tmpl.xml
Add <uses-feature android:name="android.hardware.usb.host" />
to this AndroidManifest.tmpl.xml at a good position.
Build the project again and it should pass.