Android 三星s4上的安卓BLE通知

Android 三星s4上的安卓BLE通知,android,bluetooth-lowenergy,samsung-mobile,Android,Bluetooth Lowenergy,Samsung Mobile,我正在使用google BLE sdk开发一个BLE应用程序, I测试三星s4(4.3)、索尼z1紧凑型(4.3)、htc新款(4.4) 但只有三星s4不正常 问题是何时调用setCharacteristicNotification(布尔启用) 如果我收到onDescriptorWrite回拨,则大约5~6秒后开始获取通知数据 我将得到gatt服务断开回调,我的日志只输出9次,正常情况下 日志将输出42次 对不起,我的英语很差, 我只是使用我的代码和日志来帮助任何人理解我的问题 setChara

我正在使用google BLE sdk开发一个BLE应用程序, I测试三星s4(4.3)、索尼z1紧凑型(4.3)、htc新款(4.4) 但只有三星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;

}
特征改变

@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): android.bluetooth.BluetoothGatt@436e0190 gatt
03-30 18:33:51.055: I/BluetoothLeService(8240): android.bluetooth.BluetoothGattDescriptor@436f8bf0 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 [B@436fd2f0
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 [B@43700d80
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 [B@437044f8
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 [B@43707d00
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 [B@4370b488
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 [B@4370eba0
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 [B@43712178
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 [B@437157b0
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 [B@43718d88
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

从日志中定义服务器断开连接呼叫。因此,可能有一段时间ble服务器断开连接(在ble服务器中定义一段时间)。所以,如果三星设备需要时间来读取通知数据,请自行断开连接。

启用通知后,只需显式读取一次,如以下三星设备代码所示

变通

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

通知将开始。当双向通信(客户端到服务器和服务器到客户端在同一字符上连续)时,Tt工作,但不工作。

是的,如果我使用写入/读取/通知,则s4将在30秒后断开,但当我调用setCharacteristicNotification时,数据传输没有完成,这是我的问题。真奇怪你解决过这个问题吗?我们可以在多个设备上复制。谢谢你的回复,我可以解决这个问题。问题出现在我的设备上固件设置变量错误您在固件中更改了什么设置以使其正常工作?我使用ti cc2541并修改默认值\u CONN\u PAUSE\u PERIPHERAL和GAPROLE\u PARAM\u UPDATE\u启用两者