0

我有一系列蓝牙耳机,希望能够直接连接到他们的 AVRCP 配置文件。

主要的症结在于没有公开可访问的方法来构建 L2CAP 套接字。从理论上讲,下面的代码应该可以工作,但是我收到了 permssion denied 错误。
我的清单中有这些:

<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。有没有人有幸说服 Android 蓝牙建立除 RFCOMM 之外的任何连接类型?和/或是否有可能取得更大成功的不同方法?

(PS:addln 只是向文本视图发送消息,所以我可以看到发生了什么)

4

0 回答 0