Using HTC's Bluetooth LE library in Xamarin, is this possible?

305 Views Asked by At

Here is the target: Create an Android app (Android 4.2) for HTC phones that uses Bluetooth LE to communicate with other BTLE devices. I have to use the HTC proprietary Bluetooth LE java library.

I have done the following:

  • Created an Java Bindings Library project that uses the "com.htc.android.bluetooth.le.gatt.jar" and "com.broadcom.bt.jar" files. This outputs as expected (I believe) with no modifications to the Metadata.xaml, etc.

  • Created an Android Class Library that basically translates all of the java binding methods into friendlier methods (ie. Discovery LE devices, provide a list of them, all simple connections, read/write to them). This project builds just fine. I have the reference to the outputted DLL from the binding library in this project.

  • Created an Android Application (Android 4.2; I would use 4.3 and be done with this, but that's not the objective). This application references the above Android Class library for use.

Problem: As soon as I attempt to build, I get all sorts of errors:

package com.htc.android.bluetooth.le.gatt does not exist
Line 5 : "extends com.htc.android.bluetooth.le.gatt.BleClientProfile"
    in HTCBleClientProfile.java

It actually complains about that for all the outputted java files. Slight variations to what is exactly being extended upon.

So I thought, what if I just move over the generated java files that the binding project created? I did that, and all work required for referencing to be right, but ended up with a different errors.

First thing I did was move over the generated class files. All the classes had attributes like the following:

namespace Com.Htc.Android.Bluetooth.LE.Gatt {

// Metadata.xml XPath class reference: path="/api/package[@name='com.htc.android.bluetooth.le.gatt']/class[@name='BleAdapter']"
[global::Android.Runtime.Register ("com/htc/android/bluetooth/le/gatt/BleAdapter", DoNotGenerateAcw=true)]
public partial class BleAdapter : global::Java.Lang.Object {
  /*...*/
}

If I left all the classes alone, no *.java file would be generated in the application project, resulting in something like "No Class Found" errors during runtime.

So I adjusted the "DoNoGenerateAcw" to false, which lead to the *.java files to finally generated.

At this point, now I'm getting errors for every constructor that takes in parameters for all those classes I moved in:

Object() in java.lang.object cannot be applied to (com.htc.android.bluetooth.le.gatt.GattID)

That's just one of the many different errors. But they all are the same in one respect: "Object() in java.lang.object cannot be applied to (some type)". So I reverted all the way back to the point of me referencing the DLL (which leads me back to package errors).

Does anyone have an idea of what I could do to resolve this? I have emailed Xamarin for help and also HTC for some possible solutions (like the Java source so I can port it myself to C# for this app).

Thank you in advance!

0

There are 0 best solutions below