How to connect webapp to a bluetooth enabled printer.
Basically there are 2 avenues to do that : a) going native and b) the web bluetooth api
This involves using PhoneGap or Cordova, plus installing a plugin to make the bluetooth capacities of the mobile target platform available in the js world.
I found this plugin on github, a cordova plugin, so used cordova rather than phonegap.
The install sequence for a clean install of everything looks something like
install cordova : npm install -g cordova
install pre-requisites : see https://cordova.apache.org/docs/en/latest/guide/platforms/android/index.html#requirements-and-support
java development kit (jdk)
android studio / android sdk
set environment and path variables
create app structure
create app : cordova create bluetoothprinter com.smartmobilestudio.bluetoothprinter BluetoothPrinter
cordova plugin add https://github.com/srehanuddin/Cordova-Plugin-Bluetooth-Printer.git
create remainder of app
add platform : cordova platform add android
create SMS project
copy SMS project output into the cordova app structure (www directory)
build app : cordova build android
install apk file on android
Amazingly this all works out.
Some gotcha's :
- environment and path variables don't allow spaces, so for instance .../Program Files/... has to be shortened to .../Progra~1/...
- cordova now requires plugins to have their own package.json file. The selected plugin doesn't have that, so I had to download the git repository, create a package.json file and install the plugin from local (cordova plugin add cordova-plugin-bluetooth-printer --save --searchpath ../plugin)
- the SMS project needs these entries in its template index file
and compile may end up in errors. However the cordova build process takes care of that and produces a viable apk file.
It is a bit of a process to go through, but works out well in the end.