NearBee SDK for Android
Clone or download
Kislay
Kislay Version 1.1.4
Latest commit 2fae64e Dec 5, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
NearBeeSDKSample Version 1.1.4 Dec 5, 2018
.DS_Store Init sample app Nov 2, 2018
.gitignore Init sample app Nov 2, 2018
LICENSE Initial commit Nov 2, 2018
README.md Version 1.1.4 Dec 5, 2018

README.md

NearBee SDK for Android

You will need an API key for the NearBee SDK service to work.

Integration with your existing project in Android Studio

In the build.gradle file of the app, add the following in the dependencies section:

dependencies {
    …
    implementation 'co.nearbee:nearbeesdk:1.1.4'
}
Latest version

Download

Permissions

NearBee requires the following permissions.

    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

Runtime permissions

Location

NearBee requires the location permission to scan for Beacons.

Usage

1. Add your API key and Orgnization ID to the AndroidManifest.xml as follows

<application>
…
…
    <meta-data
        android:name="co.nearbee.api_key"
        android:value="MY_DEV_TOKEN" />

    <meta-data
        android:name="co.nearbee.organization_id"
        android:value="123" />
…
…
</application>

2. Initialize SDK

NearBee.Builder builder = new NearBee.Builder(context)
                .setBackgroundNotificationsEnabled(true)
                .setCallBackInterval(5);
nearBee = builder.build();
Builder options
setBackgroundNotificationsEnabled(true);

Enables notifications from Nearby beacons in the Background. If any requirements are not met an error will be logged by the Background service. To change the behaviour (enabled to disabled and vice-versa) you need to re-initialize the SDK via the Builder as mentioned above.

setCallBackInterval(timeInSeconds);

Sets the time between callbacks for displaying beacon notifications in the foreground. This has no effect on the background notification behaviour.

3. Displaying available beacon notifications in Application UI

// Start scanning and get updates
nearBee.startScanning(new NearBeeListener() {
    @Override
    public void onUpdate(ArrayList<NearBeeBeacon> beaconsInRange) {
        // An updated list of beacons currently in range
    }

    @Override
    public void onBeaconLost(ArrayList<NearBeeBeacon> lostBeacons) {
        // List of beacons that went out of range
    }

    @Override
    public void onBeaconFound(ArrayList<NearBeeBeacon> foundBeacons) {
        // List of beacons that appeared after last update
    }

    @Override
    public void onError(NearBeeException exception) {
        // Any error preventing Nearbee from scanning for beacons.
        // This error must be resolved and nearBee.startScanning should be called again.
    }
});
// Stop scanning 
nearBee.stopScanning();
// Should ideally be done when the app goes to the background

4. Changing background notification state

// Change background notification state after initialization
nearBee.enableBackgroundNotifications(true);

5. Clear local beacon cache

// This clears the cache and forces the server to re-fetch beacon notifications
nearBee.clearNotificationCache();

Getting notification data from the Beacon object

// Notification title
nearBeeBeacon.getNotification().getTitle();
// Notification description
nearBeeBeacon.getNotification().getDescription();
// Notification url
nearBeeBeacon.getNotification().getEddystoneURL();
// Notification icon url
nearBeeBeacon.getNotification().getIcon();

Launch the url associated with the beacon

nearBeeBeacon.launchUrl(context);