Android Support
We have brand new support on Android as of February 2013. It of course is compiled using Xamarin's MonoDroid toolset. http://xamarin.com/
There is support for Radio, DeviceInfo, Client.Connect, sending and receiving data, Discovering known devices, and Listener. It has been tested on a Nexus 7 and a Samsung Tab 2 7.0 device.
The library project file is in *...\ITH.Net.Android* The current library project file targets version 2.3, i.e. API Level 10, see below. There is a solution file at *...\AndroidAaaa*
Test tool
A version of my cross-platform testing app has been created in *...\Testing\AndroidMenuTesting* and the ~140 commands are displayed in the AppBar menu system. Press your device menu button to open that, on most devices with the vertical three dots at bottom-right. A few buttons provide shortcuts GetAllRadios, GetDeviceInfo, FlagsDiscover, Connect-SimpleClosingFirst, and Listen. See the screenshot below.
Android Permissions
http://developer.android.com/reference/android/bluetooth/BluetoothAdapter.html#startDiscovery()
"Note: Most methods require the BLUETOOTH permission and some also require the BLUETOOTH_ADMIN permission"
We also need permission INTERNET because we use NetworkStream. If that becomes a problem we can maybe look at a workaround.
{anchor:androidApiLevel}
Details
Things not supported include:
Radio: Class of Device, versions, setting mode.
DeviceInfo: Setting name, LastUsed, Connected, versions, GetServiceRecords, SetServiceState, and InstalledServices.
Client.Connect: Available, DataAvailable, Connected, Client, LingerState, and LinkKey/Policy.
Discovery Devices:
Listener: Publishing custom Service Records, listening on a specific port number, and setting Service Class bits, LocalEndPoint is blank, and Pending. (Setting Service Name is supported.)
Security: No support.
Android API Level
We've used only functions from Android API Level 10, i.e. GINGERBREAD_MR1. We lose BluetoothSocket.isConnected by not using Level 14, which affects BluetoothClient.Connected. (We could probably get down to Level 5, if using createInsecureRfcommSocketToServiceRecord and listenUsingInsecureRfcommWithServiceRecord weren't required).
http://developer.android.com/guide/topics/manifest/uses-sdk-element.html#ApiLevels
{anchor:todo}
To Do
DONE. Support Device Discovery. So change AndroidBthClient to be a subclass of CommonDiscoveryBluetoothClient, create and register an Android BroadcastReceiver in AndroidBthInquiry which calls back whenever a device-found event occurs. That will provide support for both in-range and live discovery.
DONE Check what Finalizers are required. Listener, and BluetoothClient/Stream.
Provide socket errors. Currently we'll just pass any Mono-Android exceptions.
Compiling
#defines
||Define||Use|
|{{ANDROID}}|Compiling to target the Mono Android platform -- not to do with Bluetooth API|
|{{ANDROID_BTH}}|Include the 32feet.NET support for Bluetooth using the Android Bluetooth API|
|{{FAKE_ANDROID_BTH_API}}|Include the Mock Android Bluetooth API classes|
Related
|{{NO_WINFORMS}}|Exclude any WinForms usage, needed for instance when targeting Android|
|{{NO_WIDCOMM}}|Hide special case Widcomm dependency checking in BluetoothFactory|
|{{NO_MSFT}}|Hide code in e.g. BluetoothWin32Authentication referencing MSFT Bluetooth structs etc|
For real use compiling for Android
As used by the preliminary project ITH.Net.Android.csproj
{{
V2;FX3_5;ANDROID;ANDROID_BTH;NO_MSFT;NO_WINFORMS;NO_WIDCOMM}} For running in the emulator add the {{FAKE_ANDROID_BTH_API}} define, which allows Radio, Devices, and Discovery currently.
For test on desktop Windows (project file FX2)
Do not reference the {{Mono.Android.dll}}. This includes Mocking of the Android API.
{{
ANDROID_BTH;FAKE_ANDROID_BTH_API}}
For -- useless?? -- compile on desktop Windows (project file FX2)
Add reference to {{Mono.Android.dll}}, along with
{{
ANDROID_BTH;NO_WINFORMS}}
The latter is required since System.Drawing.Size is also included in the Mono.Android.dll and so conflicts with that from the FCL's System.Drawing.dll.
AndroidMenuTesting screenshot