希望您能够帮助我 .

我在我的项目中,我需要将Android设备连接到使用https://source.sierrawireless.com/devices/wifi-bluetooth-modules/bc127/这个蓝牙模块的蓝牙扬声器 .

到目前为止,我设法做配对,列表,现在当我尝试连接到设备但它只是忽略它 . 我尝试了多种连接方式 . 随着 private UUID SERIAL_UUID = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB"); - 什么都没有 .

然后尝试使用设备支持的UUID supportedUuids = device.getUuids(); 什么都没有

试图保护/不安全的rfcommsocket - 没什么

所有我得到的是 W/System.err: java.io.IOException: read failed, socket might closed or timeout, read ret: -1 谷歌搜索如何避免这种情况,发现这个IOException: read failed, socket might closed - Bluetooth on Android 4.3

现在,当我尝试连接时,没有任何事情发生,设备上的LED闪烁,因为它正在寻找连接,所有我得到的日志是

getBluetoothService() called with no BluetoothManagerCallback

同时,如果我尝试连接到智能手机,它会连接,但仅在我连接的设备上显示连接状态 . 任何帮助,为什么它不会连接到扬声器?

private class ConnectThread extends Thread {

    private  BluetoothDevice mmDevice;
    private  BluetoothSocket mSocket;
    ParcelUuid[] supportedUuids;

    public ConnectThread(BluetoothDevice device) {
        Log.d(TAG, "ConnectThread(" + device + ")");
        mmDevice = device;


        // for apiVer >= 15
        if (Build.VERSION.SDK_INT >= 15){
            supportedUuids = device.getUuids();
        }else if (Build.VERSION.SDK_INT < 15){
            // for apiVer < 15
            try {
                Class cl = Class.forName("android.bluetooth.BluetoothDevice");
                Class[] params = {};
                Method method = cl.getMethod("getUuids", params);
                Object[] args = {};
                supportedUuids = (ParcelUuid[])method.invoke(device, args);
            }
            catch (Exception e) {
                // no op
                Log.e("uuids", "Activation of getUuids() via reflection failed: " + e);
            }
        }

        if(supportedUuids.length > 0){
            for( int i=0; supportedUuids.length > i; i++){
                Log.d("UUID", "uuid"+supportedUuids[i].toString());
            }
            SERIAL_UUID = supportedUuids[0].getUuid();
        }


        try {
            mSocket = mmDevice.createInsecureRfcommSocketToServiceRecord(SERIAL_UUID);
        } catch (Exception e) {Log.e("","Error creating socket");}



    }

    public void run() {
        try {
            mSocket.connect();

            Log.e("","Connected");
        } catch (IOException e) {
            Log.e("",e.getMessage());
            try {
                Log.e("","trying fallback...");

                mSocket =(BluetoothSocket) mmDevice.getClass().getMethod("createInsecureRfcommSocket", new Class[] {int.class}).invoke(mmDevice,2);
                mSocket.connect();

                Log.d( TAG, "I am connected now");
            }
            catch (Exception e2) {
                Log.e("", "Couldn't establish Bluetooth connection!");
            }
        }



    }