0

I have a collection of bluetooth earpieces and wanted to be able to connect directly to their AVRCP profile.

The main sticking point is that there is no publicly accessible way to construction an L2CAP socket. In theory the code below ought to work, but I am getting a permssion denied error.
I do have these in my manifest:

<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

The code snippet is here:

private BluetoothSocket createL2CAP(BluetoothDevice bd, UUID uuid) {
    BluetoothSocket result = null;
    try {
        c=BluetoothSocket.class.getDeclaredConstructor(int.class,int.class,boolean.class,boolean.class, BluetoothDevice.class,int.class,ParcelUuid.class);
        result=(BluetoothSocket) c.newInstance(BluetoothSocket.TYPE_L2CAP, -1, true, true, bd, -1, new ParcelUuid(uuid));
    } catch (NoSuchMethodException e) {
        addln("BluetoothSocket: No Such Constructor");
    } catch (IllegalAccessException e) {
        addln("BluetoothSocket: Illegal access");
    } catch (InvocationTargetException e) {
        addln("BluetoothSocket: Target exception "+e.getMessage());
    } catch (InstantiationException e) {
        addln("BluetoothSocket: "+e.getMessage());
    }
    return result;
}

It's finding the constructor, but throwing the IllegalAccessException. Has anyone had any luck persuading Android Bluetooth to make any connection type other than RFCOMM? And/or is there a different approach which may have more success?

(PS: addln is just sending messages to a textview so I can see what is happening)

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
Robbie Matthews
  • 1,404
  • 14
  • 22

0 Answers0