【问题标题】:Flutter how to check if there is a device connected to my device via bluetoothFlutter如何检查是否有设备通过蓝牙连接到我的设备
【发布时间】:2020-08-30 23:24:48
【问题描述】:
我正在编写一个使用蓝牙连接的颤振应用程序。我想知道我的设备是否通过蓝牙连接到另一台设备。我想问是否有类似蓝牙的互联网连接如果没有我想知道是否有方法可以替换它。
我的应用程序具有打开蓝牙的角色,我是否已关闭,然后设备蓝牙状态是否已连接到另一台设备。
void checkconnectivity() async{
//check bluetooth connectivity
}
【问题讨论】:
标签:
android
ios
flutter
dart
bluetooth
【解决方案1】:
你可以使用这个包bluetooth
例子:
/// Create a connection to the device
var deviceConnection = flutterBlue.connect(device).listen((s) {
if(s == BluetoothDeviceState.connected) {
// device is connected, do something
}
});
/// Disconnect from device
deviceConnection.cancel();