2014-03-30 61 views
1

我使用谷歌BLE SDK, 我對三星S4(4.3),索尼Z1緊湊型(4.3),HTC新(4.4) 但只有三星檢驗關於BLE應用工作S4剛異常的Android BLE的通知三星S4

問題調用時setCharacteristicNotification(布爾啓用) 如果我得到onDescriptorWrite回撥,然後開始得到通知約5〜6秒 我會得到GATT服務斷開回調的數據,以及我的日誌只輸出9倍,正常 日誌會輸出42次,

對不起,我的英文很差, 我只是用我的代碼和日誌幫助的人能理解我的問題

setCharacteristicNotification

public boolean setCharacteristicNotification(boolean enabled){ 


     if (mBluetoothAdapter == null || mBluetoothGatt == null) { 
      Log.w(TAG, "BluetoothAdapter not initialized"); 
       return false;  
     } 

     BluetoothGattService Service = 
       mBluetoothGatt.getService 
       (UUID.fromString(GattAttributes.SONOSTAR_SENSOR_UUID)); 
     if (Service == null) { 
      Log.e(TAG, "service not found!"); 
      return false; 
     } 

     BluetoothGattCharacteristic characteristic = 
       Service.getCharacteristic 
       (UUID.fromString(GattAttributes.SONOSTAR_NOTIFY_R)); 

     final int charaProp = characteristic.getProperties(); 

     if ((charaProp | BluetoothGattCharacteristic.PROPERTY_NOTIFY) > 0) { 
      mBluetoothGatt.setCharacteristicNotification(characteristic, enabled); 

      BluetoothGattDescriptor descriptor = characteristic.getDescriptor(
        UUID.fromString(GattAttributes.CLIENT_CHARACTERISTIC_CONFIG)); 
      descriptor.setValue(BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE); 

      mBluetoothGatt.writeDescriptor(descriptor); 

      return true; 
     } 

    return false; 

} 

onCharacteristicChanged

@Override 
    public void onCharacteristicChanged(BluetoothGatt gatt, 
      BluetoothGattCharacteristic characteristic) 
    { 

     Log.i(TAG, "on notify" +""); 
      NOTIFY_DATA_ARRAY.add(characteristic.getValue()); 
      Log.i(TAG, NOTIFY_DATA_ARRAY.size() + " "+characteristic.getValue()); 
    } 

我的日誌

03-30 18:33:50.985: D/BluetoothGatt(8240): setCharacteristicNotification() - uuid: 0000ffb5-0000-1000-8000-00805f9b34fb enable: true 
03-30 18:33:50.985: D/BluetoothGatt(8240): writeDescriptor() - uuid: 00002902-0000-1000-8000-00805f9b34fb 
03-30 18:33:51.055: D/BluetoothGatt(8240): onDescriptorWrite() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:51.055: I/BluetoothLeService(8240): [email protected] gatt 
03-30 18:33:51.055: I/BluetoothLeService(8240): [email protected] descriptors 
03-30 18:33:51.055: I/BluetoothLeService(8240): 0 status 
03-30 18:33:51.055: D/BluetoothLeService(8240): Callback: Wrote GATT Descriptor successfully. 
03-30 18:33:51.545: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:51.545: I/BluetoothLeService(8240): on notify 
03-30 18:33:51.545: I/BluetoothLeService(8240): 1 [[email protected] 
03-30 18:33:52.030: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:52.035: I/BluetoothLeService(8240): on notify 
03-30 18:33:52.035: I/BluetoothLeService(8240): 2 [[email protected] 
03-30 18:33:52.520: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:52.520: I/BluetoothLeService(8240): on notify 
03-30 18:33:52.520: I/BluetoothLeService(8240): 3 [[email protected] 
03-30 18:33:53.055: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:53.055: I/BluetoothLeService(8240): on notify 
03-30 18:33:53.055: I/BluetoothLeService(8240): 4 [[email protected] 
03-30 18:33:53.545: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:53.545: I/BluetoothLeService(8240): on notify 
03-30 18:33:53.545: I/BluetoothLeService(8240): 5 [[email protected] 
03-30 18:33:54.030: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:54.030: I/BluetoothLeService(8240): on notify 
03-30 18:33:54.030: I/BluetoothLeService(8240): 6 [[email protected] 
03-30 18:33:54.520: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:54.520: I/BluetoothLeService(8240): on notify 
03-30 18:33:54.520: I/BluetoothLeService(8240): 7 [[email protected] 
03-30 18:33:55.055: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:55.055: I/BluetoothLeService(8240): on notify 
03-30 18:33:55.055: I/BluetoothLeService(8240): 8 [[email protected] 
03-30 18:33:55.540: D/BluetoothGatt(8240): onNotify() - Device=20:CD:39:90:A2:9B UUID=0000ffb5-0000-1000-8000-00805f9b34fb 
03-30 18:33:55.540: I/BluetoothLeService(8240): on notify 
03-30 18:33:55.545: I/BluetoothLeService(8240): 9 [[email protected] 
03-30 18:34:20.310: D/BluetoothGatt(8240): onClientConnectionState() - status=0 clientIf=6 device=20:CD:39:90:A2:9B 
03-30 18:34:20.310: I/BluetoothLeService(8240): Disconnected from GATT server. 
03-30 18:34:20.320: I/HomeActivity(8240): ACTION_GATT_DISCONNECTED onReceive 
03-30 18:34:20.395: E/ViewRootImpl(8240): sendUserActionEvent() mView == null 
+0

你有沒有解決過這個問題?我們可以在多個設備上重現它。 –

+0

謝謝你的回覆,即時解決這個問題。 問題發生在我的設備上固件設置變量是錯誤的 – BearrrXD

+0

您在固件中更改了哪些設置以使其工作? –

回答

0

從你的日誌定義服務器斷開呼叫。所以可能會有一段時間無法連接服務器(有時在ble服務器中定義)。因此,如果三星設備需要時間閱讀通知數據設備斷開它自己。

+0

是的,如果我使用寫/讀/通知,然後s4將在30秒後斷開,但是當我呼叫setCharacteristicNotification, 數據傳輸沒有完成,那是我的問題。 這很奇怪 – BearrrXD

0

啓用通知後,只需顯式讀取一次,如下面的代碼爲三星設備所示。

變通

  try { 
      Thread.sleep(2000); 
     } catch (InterruptedException e) { 
      // TODO Auto-generated catch block 
      e.printStackTrace(); 
     } 
     mBluetoothGatt.readCharacteristic(characteristic); 

通知將啓動。當通信正在進行時,Tt工作但不工作(客戶端到服務器和服務器到客戶端持續在同一個特徵上)。