【问题标题】:Detect when a device gets unpaired from the bluetooth检测设备何时与蓝牙取消配对
【发布时间】:2020-04-05 09:54:35
【问题描述】:

我正在开发一个项目,该项目需要在蓝牙配对模式下的设备未配对时触发通知。 (简而言之,如果设备未配对,应用程序会发送通知)。我找不到任何可以引导我构建解决方案的代码或视频。任何帮助将不胜感激。

【问题讨论】:

标签: android android-bluetooth


【解决方案1】:

你的代码需要做很多事情:

1-A BroadCastReceiver,它将检查(或侦听)蓝牙配对的状态并通过启动通知服务进行响应

2-A NotificationService 将构建您想要的通知

检查此链接以了解: https://devdeeds.com/android-kotlin-create-and-schedule-notification/

检查未配对的设备:

 Set<BluetoothDevice> pairedDevices = mBluetoothAdapter.getBondedDevices();
// If there are no paired devices
if (pairedDevices.size() < 0) {
    //set here your code that will hit the notification
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-10
    • 2013-05-16
    • 1970-01-01
    • 2021-04-26
    • 2021-12-26
    • 1970-01-01
    相关资源
    最近更新 更多