I am developing an app,which is publishing messages and subscribe using Google Nearby Messages API.The documentation says Because the Nearby Messages APIs have the potential to impact battery life, they should only be used from a foreground activity (with the exception of BLE background subscribe).
But is it still possible?
And what strategy to use to achieve maximum distance?
Thx.
Answer to your question, on the official documentation
Sample GitHub Google
Google Solution
The following code snippet demonstrates handling the intent in the BeaconMessageReceiver class.
When the subscription is no longer required, your app should unsubscribe by calling Nearby.getMessagesClient(Activity).unsubscribe(PendingIntent).
A solution to use BLE
Publish