Chandra Gopalaiah
Chandra Gopalaiah

Reputation: 13

How to get notified in the app if the app is not running when a BLE device sends data to Android phone

I am developing a mobile app for Android where I will be receiving data from BLE device. Everything seems to be working till now, but how do get notified of data received from BLE device when the application is not running at all?

One solution I'm thinking is to spin up a new system service that keeps running all the time which can monitor for any data that is being sent by BLE device. But I'm not sure if this is going to work at all.

I'm looking for some recommendations on how to achieve this? or at the very least would like to know if at all if this is possible in Android for BLE?

Thanks in advance.

Upvotes: 1

Views: 103

Answers (2)

Emil
Emil

Reputation: 18452

You need to have your app running to listen to BLE stuff.

One way of doing that is to have a Foreground Service somewhere in the app process (https://developer.android.com/guide/components/services.html#Foreground). Then it's up to you how you send the data between components inside your app. You can either use broadcasts or implement listeners which are registered (and de-registered) by some component by calling some methods in your BLE code. The listeners are then called by your BLE code when you have something to report.

Upvotes: 0

Rajesh N
Rajesh N

Reputation: 6683

Android has given best documentation for it check it they have implemented broadcast receiver and service for that

Upvotes: 1

Related Questions