移动应用程序是否可以连接到BLE设备,并在后台保持连接状态数小时? [英] It's possible for a mobile app connect to a BLE device and keep the connection alive for hours in background?

查看:202
本文介绍了移动应用程序是否可以连接到BLE设备,并在后台保持连接状态数小时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一台需要在夜间启动的设备,这要归功于移动应用程序发送的蓝牙命令.是否有可能在应用程序处于后台状态时发送此命令,并持续监视设备(例如,接收数据),例如30分钟?

如果可能,在iOS和Android中实现此功能的方式是什么?

更新:考虑一个睡眠跟踪设备;问题不应该是整夜扫描,因为用户必须在睡觉前连接设备(并最终尝试自动重新连接到已知设备,而无需扫描).我在问是否有可能保持连接并发送/接收数据,例如整夜更新内部数据库.

解决方案

有关Android BLE系统开发的几件事情,请阅读以下内容以获取更多信息:

  • 长时间运行的扫描将转换为机会扫描. (30分钟).
  • 关于后台进程取决于所需的服务类型.您可以通过通知启动前台服务,也可以启动始终在后台运行且无通知的作业.

    如果您可以更精确地了解系统的工作方式,我可以给出更详细的解释.

    We have a device that need to be started at night, the device is started thanks to a bluetooth command sent by a mobile application. It's possible to send this command while the app is in the background and keep monitoring the device (i.e. receiving data), for example, for 30 minutes?

    If it's possible what would be the ways to implement this feature in iOS and Android?

    Update: Think about a sleep tracking device; the problem shouldn't be to scan all night because the user must connect the device before go to bed (and eventually try to automatically reconnect to a known device, without the need to scan). I'm asking if it's possible to stay connected and send/receive data while, for example, updating an internal database all night.

    解决方案

    Several thing to take into account about Android BLE system development, read this for more information: https://blog.classycode.com/undocumented-android-7-ble-behavior-changes-d1a9bd87d983

    BLE Scanning has an abuse prevention since Android 7. What does this means?

    1. Prevention for an app stopping and starting BLE scans more than 5 times in a window of 30 seconds.

      1. Long-running scans are converted into opportunistic scans. (30 minutes).

    About the background process depends on what type of service you want. You can start a foreground service with a notification or you can start a Job which runs always in the background with no notification.

    If you can be more precise on how the system is going to work I can give a more detailed explanation.

    这篇关于移动应用程序是否可以连接到BLE设备,并在后台保持连接状态数小时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆