Tsunaze
Tsunaze

Reputation: 3254

Detect Beacon (Eddystone) with Android Nearby API

I'm trying to detect beacons around me, but with the Nearby API, i can't seem to find them.

I'm using this method to detect nearby devices :

public void startDiscovery(String serviceId, final OnDiscoveryListener l) {

    Nearby.Connections.startDiscovery(googleApiClient, serviceId, Connections.DURATION_INDEFINITE, new Connections.EndpointDiscoveryListener() {
        @Override
        public void onEndpointFound(String endpointId, String deviceId, String serviceId, String endpointName) {
            if (l != null) {
                l.onEndpointFound(endpointId, deviceId, serviceId, endpointName);
            }

        }

        @Override
        public void onEndpointLost(String s) {
            if (l != null) {
                l.onEndpointLost(s);
            }
        }
    })
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(Status status) {
                    if (l != null) {
                        l.onResult(status);
                    }
                }
            });
}

The listener looks like this :

public interface OnDiscoveryListener {
    public void onResult(Status status);

    public void onEndpointFound(String endpointId, String deviceId, String serviceId, String endpointName);

    public void onEndpointLost(String s);
}

But i can't detect anything

Upvotes: 5

Views: 6261

Answers (4)

Ovidiu Latcu
Ovidiu Latcu

Reputation: 72341

Yes, you can discover Eddystone beacons using the Nearby API. But to detect beacons you have to use the Nearby Messages API not the Nearby Connections API, as @Andrew Bunner also mentions.

To be able to detect the beacons using NearbyMessagesAPI you will have to also register the beacons with Google first, and than configure them to have a message payload associated with them.

You can find all the steps in my blog post or this other answer I posted.

Upvotes: 0

JimBobBennett
JimBobBennett

Reputation: 2159

This may sound like an odd thing - but try turning you wifi on and off. A lot of cheaper devices are really bad with bluetooth and fail to connect, but for some reason turning wifi off and on fixes it for a while.

I was having a similar problem - everything in my code was correct but not detecting beacons. I even tried with the manufacturers app, and theirs also couldn't detect the beacon (but their iPhone version did). I turned my wifi off, then back on again and the manufacturers app worked and so did mine.

Upvotes: 0

Andrew Bunner
Andrew Bunner

Reputation: 235

I work on the Nearby API at Google. The code snippet above uses the Nearby Connections API--which is actually geared towards different use-cases. To work with Eddystone, use the Nearby Messages API. Here's an example of using Nearby Messages to subscribe to the presence of beacons

Note that you need to first associate a Message payload with the beacon using the Proximity Beacon API.

Upvotes: 4

Benjamin M.
Benjamin M.

Reputation: 604

Even though Google advertised the usage of the Nearby API to detect beacons around us :

The Nearby API for Android and iOS makes it easier for apps to find and communicate with nearby devices and beacons

Source : http://android-developers.blogspot.be/2015/07/lighting-way-with-ble-beacons.html

I wasn't able to use the Nearby API to detect Eddystone beacons. I will describe bellow all the information I have gathered during my research hoping this might save some people some time.

I had setup about the same code as you to detect Estimote beacons but I wasn't able to find the Service ID to provide to Nearby.Connections.startDiscovery() to make it detect my beacon (I tried to use the beacon UUID and some variants without success).

I found on Estimote's website that you need to update the beacon firmware to be able to configure it as an Eddystone beacon : http://developer.estimote.com/eddystone/#configure-estimote-beacons-to-broadcast-eddystone. Mine wasn't so I did it.

Nevertheless, that didn't solve my problem and I was still unable to detect the beacon using the Nearby API. I tried setting it as a Eddystone-UID and a Eddystone-URL and tried several combination (based on the information provided by the Estimote app) as Service ID unsuccessfully.

A more deeper look into the Nearby API's documentation shows that Google doesn't mention anything about beacons nor Eddystone in their Nearby API documentation (https://developers.google.com/nearby/connections/overview) and Google's sample about beacons is not using the Nearby API at all : https://github.com/google/beacon-platform/tree/master/samples/android

Yet, they do mention that Nearby Messages will allow rich interaction such as "collaborative editing, forming a group, voting, or broadcasting a resource" and is coming soon :

Coming Soon: The Nearby Messages API will be available in Google Play service 7.8. This site will be updated with the complete API documentation when the new version is available.

Source : https://developers.google.com/nearby/

My understanding is the support for beacons will be available with the Google Play Services 7.8 since the beacons are broadcasting resources.

In the meantime, if you still wish to be able to detect Eddystone beacons around you, you can use Estimote's Android SDK : https://github.com/estimote/android-sdk#quick-start-for-eddystone or implement the same code as Google's Beacon Proximity sample : https://github.com/google/beacon-platform/tree/master/samples/android

Upvotes: 2

Related Questions