3

我的應用程序在連接到BLE設備時遇到問題。在應用程序所做的每個連接嘗試中,都會在OnConnectionStateChange()方法中獲取錯誤代碼0x0006(請求不支持)。我已經嘗試過藍牙關/開,但仍然出現相同的錯誤。Android BLE錯誤0x06請求不支持

我在LG D410(Android 5.0.2)中遇到了這個問題。在將我的LG手機升級到5.0.2後,應用程序開始出現此錯誤。 我的應用程序工作正常與三星Galaxy S4(Android 5.1),Nexus 5(Android 6.0)。

爲什麼我會收到此錯誤?可以做些什麼來解決它?

這是錯誤的日誌:

02-26 05:30:53.919 D/MyBluetoothClass-1392940(21607): trying to connect with address: 78:A5:04:86:D4:16 02-26 05:30:53.944 D/MyBluetoothClass-1392940(21607): Create a new GATT connection. 02-26 05:30:53.945 D/BluetoothGatt(21607): connect() - device: 78:A5:04:86:D4:16, auto: true 02-26 05:30:53.945 D/BluetoothGatt(21607): registerApp() 02-26 05:30:53.945 D/BluetoothGatt(21607): registerApp() - UUID=a81c9b62-f822-4e42-9af0-752a8eab82a1 02-26 05:30:53.947 D/BluetoothGatt(21607): onClientRegistered() - status=0 clientIf=5 02-26 05:30:53.947 D/MyBluetoothClass-1392940(21607): Connection attempt started; results reported asynchronously 02-26 05:30:53.947 D/BluetoothGatt(21607): refresh() - device: 78:A5:04:86:D4:16 02-26 05:30:53.950 D/BluetoothGatt(21607): onClientConnectionState() - status=6 clientIf=5 device=78:A5:04:86:D4:16 02-26 05:30:53.951 D/MyBTGattCallback(21607): onConnectionStateChange, newState: 0 02-26 05:30:53.951 E/MyBTGattCallback(21607): onConnectionStateChange status 0006 desc Req not supported

回答

0

我認爲這是在運行Android Lollipop版本BlueDroid框架的問題。 如果使用connectGatt(Context context, boolean autoConnect, BluetoothGattCallback callback) pass autoConnect = false;

使autoConnect true導致棒棒糖版本中的onClientConnectionState異常,但是,適用於棉花糖。

我做了它的工作。

@Override 
protected void onStart() { 
    super.onStart(); 
    Log.d(TAG,"connecting Gatt"); 
    bluetoothGatt = bleScanResult.getBluetoothDevice().connectGatt(this, false, callback); 
} 


@Override 
    protected void onStop() { 
     super.onStop(); 
     if (bluetoothGatt != null) { 
      Log.d(TAG,"disconnecting Gatt"); 
      bluetoothGatt.disconnect(); 
      bluetoothGatt.close(); 
      bluetoothGatt = null; 
     } 
    }