How to Show Notifications when get close to Beacon even if the app is closed?

832 Views Asked by At

I have created a mini App that helps me playing with beacons.

-what i have done so far-

So until now, I have successfully connected my App to the beacon, made 2 texts, so when I'm in the app and get in the beacon's range, the texts are changing so I can see that, move 2m away or turning the beacon upside down so it simulates Out of range, and it will show the message that I'm not in the range anymore.

So far so good, I have also successfully made the app to show notifications when I get close to the beacon, and when I click the notification to open a second activity.

-the problem-

Now, I want to show a notification when I get in the beacon's range, and the app is closed (not in the background). And after, when I click on that Notification to open my app / open App Google Play's Page if not installed.

I have searched on the internet but I haven't found anything conclusive.

If you guys know anything, or have you accomplished this task, it would be great if you can help with it. If you need more info like, my activities code I can upload it, but I considered unimportant.

Thanks!

2

There are 2 best solutions below

0
davidgyoung On BEST ANSWER

Two points:

  1. In order to make a phone react to a beacon without your app installed (e.g. to launch a PlayStore page) you need an app prei-nstalled on all phones that does this for you. The Google Play Services app used to do this through the Nearby feature, but it was discontinued in Nov. 2018 because of spam concerns. Since then this is no longer possible to do.

  2. If you do have your app installed it is a straightforward process to detect in the background and send notifications. The Android Beacon Library provides instructions here:. https://altbeacon.github.io/android-beacon-library/notifications.html

0
MikeKeepsOnShine On

You could create a BoradcastReceiver that intercept the android.intent.action.BOOT_COMPLETED.

In that way, you can launch a part of your app when you turn on the device. There, you can use a Service or something that can manage the interactions with Beacons. (BTW, i never worked with Beacons, i don't know what are the policies that you must follow).

If you don't need to launch the app when the device is turned on, anyway you can use a simple Service

Here the link to the documentation of receivers documentation.