Android BLE Notification

馋奶兔 提交于 2019-12-12 02:24:56

问题


I'm developing an android application using BLE. I've implemented all the basic operations like discovery, connection, and data transfer.

Now I was looking for BLE notifications, Is it possible to receive notification from BLE device when the application is not running (not even in background).

What I want to implement is the notification similar to GCM/FCM, we receive notifications in our app even though app is not running. So want to check if similar notification mechanism is supported by BLE devices and Android framework.

I've searched for few hours now but didn't get any proper result.

If anyone can just tell me if it is supported or not?


回答1:


Now I was looking for BLE notifications, Is is possible to receive notification from BLE device when the application is not running (not even in background).

BLE is just a communication protocol. When someone talks, someone has to listen.

What I want to implement is the notification similar to GCM/FCM, we receive notifications in our app even though app is not running. So want to check if similar notification mechanism is supported by BLE devices and Android framework.

GCM/FCM works because Google Play Services is running on the device listening for messages.

I can imagine two possible cases based on your question:

  1. If by "receive notification" you mean a change in a Bluetooth characteristic - well your app should be running already. Only you know how to talk to the BLE device.

  2. If you want to implement a location aware beacon type behavior with BLE you may be able to leverage the existing Google Nearby feature to achieve the desired effect.




回答2:


I would say no. You need to have the app running to get Bluetooth callbacks. You should simply set up a Foreground Service in your process and that will keep the app running in the background.




回答3:


If you want to receive notification event if your app is not running, you should implement Android service that continuously scan for BLE frames and ones it catch some frame that is met some parameters (for example for iBeacon it will be specific Major and Minor values; for Eddystone URL -- some specific URL etc.) -- just send intend to start your application.



来源:https://stackoverflow.com/questions/42672775/android-ble-notification

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