簡體   English   中英

Android BluetoothLEGatt BLE無法保持與設備的連接

[英]Android BluetoothLEGatt BLE not staying connected to device

我正在從Google運行示例BluetoothLeGatt應用,並且無法保持設備連接。 我覺得我有點隨機行為。 藍牙通常不會在第一次嘗試時就不連接(因此通常我幾乎想說“從不”。)

大約有50%的時間,當我按下連接按鈕時,該應用會顯示狀態為“已連接”。 但是,硬件設備的LED指示燈在連接時會點亮,並且不會點亮。 然后5或6秒后,它將斷開連接。 我懷疑它會先連接一會兒然后斷開連接,而該應用只是暫時沒有收到備忘錄。 這是logcat:

D/BluetoothGatt: connect() - device: 54:4A:16:2F:3C:F6, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=60edb0ed-90de-4d7d-b4d0-690bcc359fb7
D/BluetoothGatt: onClientRegistered() - status=0 clientIf=10
D/BluetoothLeService: Trying to create a new connection.
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=10 device=54:4A:16:2F:3C:F6
I/BluetoothLeService: Connected to GATT server.
D/BluetoothGatt: discoverServices() - device: 54:4A:16:2F:3C:F6
I/BluetoothLeService: Attempting to start service discovery:true
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=00001800-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=00001801-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetService() - Device=54:4A:16:2F:3C:F6 UUID=0000ffe0-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a00-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a01-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a02-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a03-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a04-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=00002a05-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetCharacteristic() - Device=54:4A:16:2F:3C:F6 UUID=0000ffe1-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002902-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002902-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onGetDescriptor() - Device=54:4A:16:2F:3C:F6 UUID=00002901-0000-1000-8000-00805f9b34fb
D/BluetoothGatt: onSearchComplete() = Device=54:4A:16:2F:3C:F6 Status=0
D/BluetoothGatt: onClientConnectionState() - status=0 clientIf=10 device=54:4A:16:2F:3C:F6
I/BluetoothLeService: Disconnected from GATT server.

也許有10%的時間我按下了連接按鈕,卻什么也沒看到:

D/BluetoothGatt: connect() - device: 54:4A:16:2F:3C:F6, auto: false
D/BluetoothGatt: registerApp()
D/BluetoothGatt: registerApp() - UUID=7dbe26bc-4cee-48d2-9f47-59af4edb33bb
D/BluetoothGatt: onClientRegistered() - status=133 clientIf=0
I/BluetoothLeService: Disconnected from GATT server.
D/BluetoothLeService: Trying to create a new connection.

實際連接的時間可能是30%。

這可能是硬件/固件問題。 盡管使用iPhone連接到設備時我沒有任何問題,但是我想得出一個結論,即android代碼在某處已損壞。 我可以發布所有BLE代碼,但實際上我只是下載了示例,因此我知道這沒什么壞的。

編輯 :對於那些跟蹤我的數學。 應用程序在掃描時找不到任何東西的最后10%的時間,我必須重新啟動應用程序。

編輯 :我已經從Play商店下載並嘗試了2個其他BLE應用,並獲得與我作為google示例BLE應用相同的連接問題。 android的BLE實現需要設置一些與iOS不同的設置嗎?

嘗試使用:BluetoothDevice.connectGatt(上下文上下文,布爾自動連接,BluetoothGattCallback回調,整數傳輸)

使用TRANSPORT_LE作為運輸工具。

那對我有用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM