min SDK version: 27 Android >= 8.1 Oreo
- /android-usb - android studio project - contains java files for the plugin; based on sample project USBEnumerator. Only some classes are taken from here(see: plugin.xml)
- /www - cordova plugin js
- plugin.xml - plugin config and mapping
Cordova Plugin Development Guide
How to Create a Cordova Plugin from Scratch
How to create an Android Cordova plugin for showing Toast popups
cordova plugin add git@github.com:kaizentmk/tmk-cordova-plugin-usb.git
cordova plugin add https://github.com/kaizentmk/tmk-cordova-plugin-usb.git
var success = function(message) {
alert(message);
}
var failure = function() {
alert("Error calling TmkUsb Plugin");
}
window.cordova.plugins.tmkusb.greet("World", success, failure);
maven cordova framework for gradlew build.gradlew (Module:app)
dependencies {
implementation group: 'org.apache.cordova', name: 'framework', version: '8.0.0'
}
/home/tmk/projs/tmk-cordova-plugin-usb/android-usb/app/src/main/java/com/example/androidthings/usbenum/UsbActivity.java:55: Error: Call requires API level 23 (current min is 21): android.content.Context#getSystemService [NewApi] mUsbManager = getSystemService(UsbManager.class);
usbSerialDevice.open()
-
Init broadcast receiver in initialize method. You can make it so the app will start automatically by adding an IntentFilter to the MainActivity. The IntentFilter triggers when any new device is attached. To explicitly specify the type of device by providing the vendor ID and/or product ID in an XML file.
-
Query for all connected devices. All USB slave devices have a vendor and product ID.
-
Check for matching vendor id. An Arduino’s vendor ID is always 0x2341 or 9025.
-
Request user permission to access the device
-
If permission granted open the device
-
Create serial connection and set parameters
-
Begin thread to continuously check for incomming data
-
Display/write data. Take note that reading from the device is asynchronous, so it will continuously run in the background, receiving data as soon as possible. All data received is in the form of raw bytes, so it needs to be re-encoded into a readable format such as UTF-8.
git add . && git commit -am"Tmkcordovapluginusb" && git push --force origin master