Search code examples
androidbeacongoogle-nearbygoogle-beacon-platformgoogle-proximity-api

Proximity Beacon API: Android and Nearby


My Android app is used for broadcasting of beacons, which are delivered to nearby devices with Nearby as notifications with URL links.

Google annoucned they are going to close this service.

They reccomend to use Proximity Beacons API

After reading the doc, I got that I need to register every beacon via REST-API, auth using OAuth and API (in the same time), also they say something about Google Places and so on.

It looks pretty complicated.

And I don't understand: will these beacons be delivered to nearby users through Nearby with my URL link? How it worked before.

Maybe there is a Android lib? I found this. But it's only for "scanning". I don't understand what is for. Is it impossible just broadcast beacons to other devices nearby as it was before?

Thank you


Solution

  • Google Nearby provided a way to send notifications to Android devices near your beacons even if users do not have your third-party app installed. Now that Nearby is being discontinued, this is no longer possible. You must now get a third party app installed on a device in order to send notifications to a user on beacon detection.

    The simplest way to do this is to build a basic Android app that just listens for beacons and sends a notification when one is detected. You can do this with the Google Pproximity Beacons API, which is a bit complicated because it requires registering your beacons with Google's servers, enabling the service, and embedding an API key I your app.

    A much simpler way is to use the open source Android Beacon Library, which is much more established and has no server or licensing requirement. You can read how this works here. Sending a notification on beacon detection is crazy simple. Just link to the library add this code snippet to a custom Android Application class.

    @Override
    public void onCreate() {
        super.onCreate();
        BeaconManager beaconManager = BeaconManager.getInstanceForApplication(this);
        beaconManager.getBeaconParsers().add(new BeaconParser().
                setBeaconLayout("m:2-3=0215,i:4-19,i:20-21,i:22-23,p:24-24"));
    
        Region region = new Region("com.example.myapp.boostrapRegion", null, null, null);
        RegionBootstrap regionBootstrap = new RegionBootstrap(this, region);
    }
    
    
    @Override
    public void didEnterRegion(Region region) {
        NotificationCompat.Builder builder =
                new NotificationCompat.Builder(this)
                        .setContentTitle("Beacon Reference Application")
                        .setContentText("A beacon is nearby.")
                        .setSmallIcon(R.drawable.ic_launcher);
    
         TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
         stackBuilder.addNextIntent(new Intent(this, MonitoringActivity.class));
         PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                        0,
                        PendingIntent.FLAG_UPDATE_CURRENT
                );
         builder.setContentIntent(resultPendingIntent);
         NotificationManager notificationManager =
                (NotificationManager) this.getSystemService(Context.NOTIFICATION_SERVICE);
         notificationManager.notify(1, builder.build())
    }
    

    Whichever APi you use, the critical obstacle is to get users to install your app. Unless they do so, they will not receive notifications. Google Nearby was able to accomplish this seemingly without an app by embedding itself inside the Google Play Services client app which is pre-installed on most Android devices outside China. Essentially, Google was delivering your notifications for you with their app. Now, Google is announcing it will no longer do this.

    Again, the only alternative is to build and distribute your own app that detects beacons and sends your notifications.

    Full disclosure: I am the lead developer on the Android Beacon Library open source project.