2013-08-20 91 views
0

我目前正在使用Android 4.3藍牙低功耗,我可以連接到設備,獲取服務,讀/寫服務。現在,當我嘗試連接第二臺設備時,第二臺設備的服務被接收,第一臺設備服務丟失。現在,當我嘗試連接到第一個設備的寫入/讀取特性時,沒有任何工作。Android 4.3是否支持多個BLE設備連接?

有沒有人試圖連接到多個設備。你如何初始化兩個設備的加特?

+0

我剛纔已經證實,有可能(的Nexus 4採用4.3):我已經連接到一個HR傳感器,我使用API​​ 18附帶的BLE Sample,同時連接到速度計設備,我使用了大量修改後的樣本。然而,即使我使用兩個獨立的服務(從單個服務超類派生兩個服務不起作用 - 只有一個實例存在),我無法從自己的應用程序連接到兩者。所以我猜想兩個同時連接是可能的,不知道如何從同一個活動中實現它,但一旦找到它就會發布解決方案 D – Dmitry

回答

0

我認爲SAMSUNG BLE API和Google的API都有Broadcom Ble堆棧,而Broadcom堆棧目前不支持多個ble設備。

0

我在三星BLE堆棧(星系S4)上有完全相同的行爲。我砍了三星代碼,並修復它:

類BluetoothGatt保留「所有」發現的服務的列表。對BluetoothGatt-> discoverServices的調用將清除此列表。我駕駛自己的班級並修改了該功能的行爲,只刪除了有關BluetoothDevice的服務。這是我的代碼:

public class MyBluetoothGatt extends BluetoothGatt { 

    MyBluetoothGatt(Context paramContext, BluetoothProfile.ServiceListener paramServiceListener) 
     { 
     super(paramContext, paramServiceListener); 
     } 

    public final boolean discoverServices(BluetoothDevice paramBluetoothDevice) 
     { 
     if (paramBluetoothDevice == null) 
     { 
      Log.e("BtGatt.BluetoothGatt", "discoverServices() - device is null "); 
      return false; 
     } 
     Log.d("BtGatt.BluetoothGatt", "discoverServices() - device: " + paramBluetoothDevice.getAddress()); 

     if ((d == null) || (this.f == 0)) 
      return false; 
// old code  this.h.clear(); 

//--new code 
     @SuppressWarnings("rawtypes") 
     Iterator localIterator = this.h.iterator(); 
     while (localIterator.hasNext()) 
     { 
      BluetoothGattService localBluetoothGattService; 
      localBluetoothGattService = (BluetoothGattService)localIterator.next(); 

      if (localBluetoothGattService.a().equals(paramBluetoothDevice)) 
      { 
       this.h.remove(paramBluetoothDevice); 
      } 
     }  
//end new code  


     this.d.discoverServices(this.f, paramBluetoothDevice.getAddress()); 


     return true; 
     } 

} 

我也不得不使用類編輯器中刪除一些「最後」修飾符,以便能夠dervive我自己的類。這是一個很大的黑客攻擊,但現在它運行的很好。一旦官方發佈出來,我將S4升級到android 4.3並移植我的代碼,所以手指越過這個也適用於android 4.3。

0

它應該爲所有,如果您實現不同BluetoothGatt實例和不同GattCallback爲要連接的每臺設備工作...

相關問題