Read the full documentation
Minimal implementation of the inBeacon SDK in an Android Studio project
Add JCenter to your build file's list of repositories:
repositories {
jcenter()
}
android {
...
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
implementation('com.inbeacon:android.sdk:2.+@aar'){ transitive = true }
...
}
You need to have your own application class to enable working with the inBeacon SDK.
You can't initialize in an activity: the SDK will not work correctly in the background in this case
In this class, initialize the inBeacon SDK from the onCreate of the application:
import android.app.Application;
import com.inbeacon.sdk.InbeaconManager;
public class MainApp extends Application {
@Override
public void onCreate() {
super.onCreate();
// initialize with your ClientID and Secret.
InbeaconManager.initialize(this, "<<your client Id>>", "<<client Secret>>");
}
}
You can find your client-ID and client-Secret in your account overview
Now you have to make sure MyApp
is used as the application class by adding it to your AndroidManifest.xml
:
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.inbeacon.inbeaconsdktest" >
<application android:name=".MainApp"> <!-- add android:name -->
...
</application>
</manifest>
You also need to ask the user permission to use the device FINE_LOCATION and BACKGROUND_LOCATION.
For a quick start, the inBeacon SDK contains a method askPermissions to do this, but you probably want to handle the onboarding yourself.
Include this statement in your main activity:
public class MyActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
...
InbeaconManager.getInstance().askPermissions(this);
...
For details read the full documentation or check out the Example