Android library to scan for iBeacons.
You can download the library via Gradle from the jCenter repository:
repositories {
jcenter()
}
By adding the dependency in your module level build.gradle:
dependencies {
compile 'mobi.inthepocket.android:ibeaconscanner:1.2.2'
}
It depends if you want to scan for beacons in a service or in your app how to integrate the library:
public class MyService extends Service implements IBeaconScanner.Callback
{
@Override
public void onCreate()
{
super.OnCreate();
// initialize
IBeaconScanner.initialize(IBeaconScanner.newInitializer(this).build());
IBeaconScanner.getInstance().setCallback(this);
}
}
If you want to scan for beacons in an activity, first initialize the library in your application class:
public class MyApplication extends Application
{
public void onCreate()
{
super.onCreate();
// initialize
IBeaconScanner.initialize(IBeaconScanner.newInitializer(this).build());
}
}
You need to set your Callback in your Activity, Fragment or Service, by implementing this interface:
public interface Callback
{
void didEnterBeacon(Beacon beacon);
void didExitBeacon(Beacon beacon);
void monitoringDidFail(Error error);
}
IBeaconScanner.getInstance().setCallback(this);
final Beacon beacon = Beacon.newBuilder()
.setUUID("84be19d4-797d-11e5-8bcf-feff819cdc9f")
.setMajor(1)
.setMinor(2)
.build();
Pass one or more beacons to the library to start getting enter or exit notifies:
IBeaconScanner.getInstance().startMonitoring(beacon);
IBEACON-SCANNER-ANDROID is freely distributable under the terms of the MIT license.