It's possible for a mobile app connect to a BLE device and keep the connection alive for hours in background?

ⅰ亾dé卋堺 提交于 2019-12-23 05:13:16

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/53213470/its-possible-for-a-mobile-app-connect-to-a-ble-device-and-keep-the-connection-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!