是否可以通过蓝牙建立L2CAP套接字连接?

时间:2018-07-21 10:36:10

标签: android bluetooth l2cap avrcp

我有一个蓝牙听筒集合,希望能够直接连接到他们的AVRCP配置文件。

主要问题在于,没有公开可访问的方式来构建L2CAP套接字。  从理论上讲,下面的代码应该可以工作,但是我遇到了拒绝权限错误。
我的清单中确实有这些:

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

代码段在这里:

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;
}

正在找到构造函数,但会抛出IllegalAccessException。 除了RFCOMM之外,还有谁能说服Android蓝牙建立任何连接类型?和/或有没有其他方法可能会取得更大的成功?

(PS:addln只是将消息发送到textview,所以我可以看到正在发生的事情)

0 个答案:

没有答案