1

我有一个示例应用程序,它通过蓝牙传输 30 个字符长度的数据。数据传输正确了四天,然后断开连接。然后,在几分钟后建立连接时,蓝牙连接丢失。添加 adb 日志和代码。

为什么由于设备属性更改而与平台断开连接?设备属性何时更改?设备属性变化是蓝牙连接松动的原因吗?

private static final UUID MY_UUID_SECURE = UUID.fromString("00001101-0000-1000-8000-00805F9B34FB");

private class ConnectThread extends Thread {
    private final BluetoothSocket mmSocket;
    private final BluetoothDevice mmDevice;
    private String mSocketType;

    public ConnectThread(BluetoothDevice device, boolean secure) {
        mmDevice = device;
        BluetoothSocket tmp = null;
        mSocketType = secure ? "Secure" : "Insecure";

        // Get a BluetoothSocket for a connection with the
        // given BluetoothDevice
        try {

                tmp = device.createRfcommSocketToServiceRecord(MY_UUID_SECURE);

        } catch (IOException e) {
            Log.e(TAG, "Socket Type: " + mSocketType + "create() failed", e);
        }
        mmSocket = tmp;
        Log.i("12345", "Socket set");
    }

    public void run() {
        Log.i("12345", "BEGIN mConnectThread SocketType:" + mSocketType);
        setName("ConnectThread" + mSocketType);

        // Always cancel discovery because it will slow down a connection
        mAdapter.cancelDiscovery();

        // Make a connection to the BluetoothSocket
        try {
            // This is a blocking call and will only return on a
            // successful connection or an exception
            mmSocket.connect();
        } catch (IOException e) {
            // Close the socket
            try {
                mmSocket.close();
                Log.i(TAG, "Closing Socket 3");
            } catch (IOException e2) {
                Log.e(TAG, "unable to close() " + mSocketType + " socket during connection failure", e2);
            }
            connectionFailed();
            return;
        }

        // Reset the ConnectThread because we're done
        synchronized (BluetoothChatService.this) {
            mConnectThread = null;
        }

        // Start the connected thread
        connected(mmSocket, mmDevice, mSocketType);
    }

日志:

09-12 11:16:36.230 V/BluetoothEventLoop.cpp(2255):event_filter:接收到的信号 org.bluez.Device:PropertyChanged 从 /org/bluez/3179/hci0/dev_22_89_8E_A9_50_1C

09-12 11:16:36.230 D/BluetoothEventLoop(2255):设备属性已更改

09-12 11:16:36.240 D/BluetoothA2DPStateReceiver(20246):BluetoothA2DPStateReceiver 构造函数调用()

09-12 11:16:36.245 D/BluetoothA2DPStateReceiver(20246): onReceive(): action = android.bluetooth.device.action.ACL_DISCONNECTED

09-12 11:16:36.245 D/BluetoothA2DPStateReceiver(20246): ACTION_ACL_DISCONNECTED

09-12 11:16:36.245 D/BluetoothA2DPSinkInfo(20246): checkBlackListCarkit() : isBlackListCarkit false

09-12 11:16:36.660 D/KeyguardViewMediator(2255):setHidden false

4

1 回答 1

0

可能是由于链路丢失,BT 适配器启动了属性更改命令,向上层报告链路断开。请签入多个设备。

于 2013-09-12T08:42:39.883 回答