android ble readCharacteristic需要很长时间

时间:2013-10-29 07:05:31

标签: android bluetooth

我在新的nexus 7(4.3 JSS15R)上使用bluetoothle示例(android-sdks / samples / android-18 / legacy / BluetoothLeGatt /)来测试蓝牙。我发现readCharacteristic花费了太多时间(每次读取大约1~3秒)。

首先,我点击服务项目时触发readCharacteristic。

    DeviceControlActivity.java
    ....
    private final ExpandableListView.OnChildClickListener servicesListClickListner = 
    ....
    public boolean onChildClick(ExpandableListView parent, View v, int groupPosition,
    ....
         mBluetoothLeService.readCharacteristic(characteristic);

然后在读取特征时重复readCharacteristic。

    BluetoothLeService.java
    ....
    private final BluetoothGattCallback mGattCallback = new BluetoothGattCallback() {
    ....
    @Override
    public void onCharacteristicRead(BluetoothGatt gatt,
                                     BluetoothGattCharacteristic characteristic,
                                     int status) {
        if(TEST_COUNT < 20) {
            Log.d(TAG,"onCharacteristicRead");
            readCharacteristic(characteristic);
            TEST_COUNT ++; 
        } else {
            TEST_COUNT = 0;
        }   

        /*  
        if (status == BluetoothGatt.GATT_SUCCESS) {
            broadcastUpdate(ACTION_DATA_AVAILABLE, characteristic);
        }
        */
    } 

并显示日志:

10-29 11:16:37.360: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:39.362: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:41.364: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:43.356: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:45.358: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:47.340: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:49.342: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:51.334: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:53.336: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:55.328: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:57.319: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:16:59.311: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:01.313: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:03.305: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:05.297: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:07.289: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:09.291: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:11.283: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:13.285: DEBUG/MyTest(9554): onCharacteristicRead
10-29 11:17:15.277: DEBUG/MyTest(9554): onCharacteristicRead

接收每个特征读取需要2秒钟,真的很奇怪。

我使用samsung ble sdk测试与galaxy s4相同的行为,当然还有同样的装置。但是日志显示它花在阅读上的时间更少。

10-29 11:51:19.393  I/MyTest﹕  onCharacteristicRead
10-29 11:51:19.493  I/MyTest﹕  onCharacteristicRead
10-29 11:51:19.588  I/MyTest﹕  onCharacteristicRead
10-29 11:51:19.688  I/MyTest﹕  onCharacteristicRead
10-29 11:51:19.783  I/MyTest﹕  onCharacteristicRead
10-29 11:51:19.878  I/MyTest﹕  onCharacteristicRead
10-29 11:51:19.978  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.078  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.183  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.323  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.418  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.518  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.613  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.713  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.808  I/MyTest﹕  onCharacteristicRead
10-29 11:51:20.908  I/MyTest﹕  onCharacteristicRead
10-29 11:51:21.003  I/MyTest﹕  onCharacteristicRead
10-29 11:51:21.103  I/MyTest﹕  onCharacteristicRead
10-29 11:51:21.248  I/MyTest﹕  onCharacteristicRead
10-29 11:51:21.343  I/MyTest﹕  onCharacteristicRead
10-29 11:51:21.443  I/MyTest﹕  onCharacteristicRead

是否有人遇到同样的问题?它是由新的nexus 7硬件引起的吗?还是android 4.3 sdk?

我应该怎么做才能减少readCharacteristic的花费时间?

0 个答案:

没有答案