I have smartphone without barometer and I would like to use external barometer connected to my smartphone by USB or Bluetooth. I want that each installed application could use this baromter in standard way but I don't know if it is possible. By standard way I mean that each application downloaded from google play which require barometer could use my external barometer. So solution where there is application which read measurements and share it by Intent does not staisfy me.
Adding external GPS is easier because there is android.location.LocationManager class which has a method addTestProvider so I can develop application which creates TestProvider and sets location read from USB/bluetooth by setTestProviderLocation method. The problem is that SensorManager does not offer API to add mock sensor.
Is possible to connect external barometer to Android device and share measurments to all applications.
An external USB sensor would require Android have support for the device when plugged in. Then you'll need an OTG cable to reverse the USB slave/master. Without going into kernel building, etc... on your android device install a Terminal app, plug the OTG and sensor in, and run dmesg to see if the device was detected and a driver loaded. From there you'll have to figure out what Linux support exists for your USB sensor and work on a path to get that support into an Android kernel.
If you end up having to build a new kernel, you might as well switch completely over to a whole new ROM. CyanogenMod provides complete source, build scripts and wiki on building their ROMs from scratch. Once you have a new ROM zip installing you can tweak the kernel and installed software all you want safely.
The Android kernel is close enough to the straight Linux kernel that support for pretty much anything that works on Linux can be made to work on android as long as the source for your sensor driver is available, or a precomplied binary of it is available. (also known as proprietary blobs)
Finally, assuming that you have a device with an OTG cable and the sensor appears to be detected and a driver is loaded, you'll need some tools or app to actually use the sensor. If there are Linux tools available that do what you want, see if there are precomplied ARM versions of them, or you'll have to use the Android NDK to compile them from source, if the source is available.
Why am I bothering to explain all of this? Bluetooth is overall super unreliable in Android. Also you'll need Android 5.1 at least. Google's original Bluetooth stack was garbage. (A wrapper around Bluez that had all kinds of problems, it worked ok for some uses but overall had stability problems) You need only use a heart rate monitor on a non-Samsung device to know it won't stay connected for longer than 10 seconds. Samsung brought their own Bluetooth stack in earlier devices. I've developed authentication apps using a heart rate monitor with an ECG reader, both using Bluetooth. Once my Nexus5 devices were upgraded to 5.1, everything stabilized. Google's Bluetooth problems are well known. Just Google android, and Bluetooth stack implementation.
Unless you need wireless, wired will always be better.
You do have some alternative USB options.
1) Use an Arduino or RPi tethered over USB. No special Linux drivers or kernels needed but you will need the breakout device and it will have to gateway your sensor. E.g sensor -> Arduino -> android. If it's a RPi you'll have like 4 USB ports and a full Linux kernel to work with, but power will be an issue depending on your needs. Here's a great tut on Arduino tethering from an app: http://www.allaboutcircuits.com/projects/communicate-with-your-arduino-through-android/
2) Use the IOIO OTG breakout unit to roll your own sensor into its variety of inputs. You'll be able to access the sensors from Java. They even provide an app to test everything. The unit itself also has battery power and charging support for any wired sensors. You just wire them up, plug it into your android USB and off you go. I think they're on the verge of releasing a new model as the current unit is listed as discontinued: https://www.sparkfun.com/news/2069
Anyways, good luck.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With