2016-01-22 94 views
1

我參與了一個Android APP,它與我們公司Bt芯片進行BLE連接和配對。 APP是BLE的中心角色,而Bt芯片則是BLE外設。Ble配對失敗

當APP在Android 4.4或5.0智能手機上運行時,BLE連接和配對效果良好。當APP在Android 5.1或最新版本6.0上運行時,BLE配對由錯誤代碼(錯誤代碼:13)終止,而BLE連接成功。這裏是空氣日誌:

4,148 0x50654c1d 0x0000 1 LL_VERSION_IND  24  2015/12/3 14:13:39.600368 
4,160 0x50654c1d 0x0001 2 LL_VERSION_IND  24 00:00:00.048473 2015/12/3 14:13:39.648841 
4,163 0x50654c1d 0x0002 1 LL_FEATURE_REQ  27 00:00:00.048522 2015/12/3 14:13:39.697363 
4,169 0x50654c1d 0x0003 2 LL_FEATURE_RSP  27 00:00:00.049066 2015/12/3 14:13:39.746429 
4,179 0x50654c1d 0x0004 1 LL_CONNECTION_UPDATE_REQ 0x000a 30 00:00:00.048436 2015/12/3 14:13:39.794865 
4,234 0x50654c1d 0x000b 1 LL_ENC_REQ  41 00:00:00.303755 2015/12/3 14:13:40.098620 
4,237 0x50654c1d 0x000c 2 LL_ENC_RSP  31 00:00:00.007727 2015/12/3 14:13:40.106347 
4,244 0x50654c1d 0x000d 2 LL_START_ENC_REQ  19 00:00:00.007500 2015/12/3 14:13:40.113847 
4,245 0x50654c1d 0x000e M LL_START_ENC_RSP  23 00:00:00.007273 2015/12/3 14:13:40.121120 
4,248 0x50654c1d 0x000f S LL_START_ENC_RSP  23 00:00:00.007726 2015/12/3 14:13:40.128846 
4,392 0x50654c1d 0x004a M LL_CONNECTION_UPDATE_REQ 0x0050 34 00:00:00.442275 2015/12/3 14:13:40.571121 
4,794 0x50654c1d 0x008c M LL_CHANNEL_MAP_REQ 0x0093 30 00:00:03.002545 2015/12/3 14:13:43.573666 
7,168 0x50654c1d 0x0131 M LL_CHANNEL_MAP_REQ 0x0138 30 00:00:08.043797 2015/12/3 14:13:51.617463 
10,065 0x50654c1d 0x0261 M LL_CHANNEL_MAP_REQ 0x0268 30 00:00:14.820121 2015/12/3 14:14:06.437584 
10,449 0x50654c1d 0x029d M LL_TERMINATE_IND  24 00:00:02.925044 2015/12/3 14:14:09.362628 

我轉Bt基因宿主程序(基於轉Bt基因芯片)收到CONNECTION_PARAMETER_UPDATE_COMP_IND事件,然後收到LE_DEVICE_DISCONNECT_COMP_IND事件。我想斷開BLE的操作是由Android Bt堆棧完成的。

在Android 4.4或5.0中,沒有收到CONNECTION_PARAMETER_UPDATE_COMP_IND事件,那麼有什麼關係呢,我怎麼才能在Android 5.1或6.0上使BLE配對成功。任何幫助將不勝感激。

回答

2

對於藍牙低功耗設備發現和配對有兩種方法被支持

  1. 對於奇巧版本及以下

    startLeScan() 
    

這種方法需要一個BluetoothAdapter。 LeScanCallback作爲參數

  • 對於棒棒糖版本及以上

    mBluetoothLeScanner = mBluetoothAdapter.getBluetoothLeScanner(); 
    
    mBluetoothLeScanner.startScan(filters, settings, mScanCallback); 
    

    ,你需要確定你的回調爲流得到響應

    private ScanCallback mScanCallback = new ScanCallback() { 
    @Override 
    public void onScanResult(int callbackType, ScanResult result) { 
    
    } 
    
    @Override 
    public void onBatchScanResults(List<ScanResult> results) { 
    
    } 
    
    @Override 
    public void onScanFailed(int errorCode) { 
    
    } 
    }; 
    
  • 0

    感謝你的回覆。我嘗試使用startScan方法而不是startLeScan,但問題仍然存在。這裏是代碼的一部分:

    mBluetoothScanner = mBluetoothAdapter.getBluetoothLeScanner(); 
        mBluetoothScanner.startScan(mScanCallback); 
        private ScanCallback mScanCallback = new ScanCallback() { 
        @Override 
        public void onScanResult(int callbackType, ScanResult result) { 
         final byte[] scanRecord = result.getScanRecord().getBytes(); 
         final int rssi = result.getRssi(); 
         final BluetoothDevice device = result.getDevice(); 
    
         mHandler.post(new Runnable() { 
          @Override 
          public void run() { 
           // TODO Auto-generated method stub 
           //Application analyzes data in received packet. 
           AdvertisingData adData = new AdvertisingData(scanRecord); 
           byte[] adManufacturerData = adData.getAdManufacturerData(); 
           if (adManufacturerData.length < 2) {return;} 
    
           byte[] carBrand = Arrays.copyOf(adManufacturerData, adManufacturerData.length - 2); 
           byte[] carModel = Arrays.copyOfRange(adManufacturerData, adManufacturerData.length - 2, adManufacturerData.length); 
           if (!Arrays.equals(carBrand, mManufacturerData)) {return;} 
    
           mScanningFrame.setRssiInfo(rssi); 
    
           if (rssi >= mRssi) { 
            mConnectingFrame.setCarImage(carModel); 
            mConnectedFrame.setCarImage(carModel); 
            mDisconnectedFrame.setCarImage(carModel); 
            try { 
             Thread.sleep(1000); 
            } catch (Exception e) { 
             e.printStackTrace(); 
            } 
            showFrame(mConnectingFrame); 
            mBleDevice = device; 
            mBluetoothGatt = mBleDevice.connectGatt(getApplicationContext(), false, mGattCallback); 
            mBluetoothAdapter.stopLeScan(mLeScanCallback); 
           } 
          } 
         }); 
        } 
    
        @Override 
        public void onBatchScanResults(List<ScanResult> results) { 
    
        } 
    
        @Override 
        public void onScanFailed(int errorCode) { 
    
        } 
    }; 
    

    還有其他方法可以解決這個問題,或者我錯過了什麼?謝謝