颤动的蓝色实例连接在Android中自动断开连接

时间:2019-10-29 11:58:40

标签: flutter dart bluetooth-lowenergy

我已经用BLE完成了用Flutter编写的应用程序,并且在iOS中运行良好。

但是当我在Android中运行相同的应用程序时,它无法正常工作。因此,我检查了日志,发现该应用程序未稳定地连接到Bluetooth设备,并且一旦连接,它就会断开连接。

所以我写了一段代码来侦听蓝牙连接中的状态变化,并在状态更改断开时重新连接,并在日志中发现它像循环一样保持连接和断开状态。

请注意,这在iOS中也能正常工作。

Launching lib/main.dart on TRT L21A in debug mode...
Built build/app/outputs/apk/debug/app-debug.apk.
I/flutter (10374): getHOME, statusCode = 200
I/flutter (10374): Body Batch: {status: success, target_steps: 10000, today_steps: 0, calorie_target: 2000, today_calories: 0, totaldistance: 0, team_leader: no}
I/hwaps   (10374): JNI_OnLoad
I/BluetoothAdapter(10374): getBluetoothLeScanner
I/flutter (10374):
I/BluetoothAdapter(10374): getBluetoothLeScanner
I/BluetoothGatt(10374): connect is called
I/BluetoothGatt(10374): connect is called
I/art     (10374): Do partial code cache collection, code=30KB, data=30KB
I/art     (10374): After code cache collection, code=30KB, data=30KB
I/art     (10374): Increasing code cache capacity to 128KB
I/flutter (10374): State is BluetoothDeviceState.disconnected
I/BluetoothGatt(10374): connect is called
I/flutter (10374): State is BluetoothDeviceState.disconnected
I/BluetoothGatt(10374): connect is called
I/flutter (10374): State is BluetoothDeviceState.disconnected
I/BluetoothGatt(10374): connect is called
I/flutter (10374): State is BluetoothDeviceState.connected
I/flutter (10374): State is BluetoothDeviceState.connected
I/flutter (10374): State is BluetoothDeviceState.connected
I/flutter (10374): State is BluetoothDeviceState.connected

0 个答案:

没有答案