-
Notifications
You must be signed in to change notification settings - Fork 0
Android
Prateek Srivastava edited this page Nov 29, 2017
·
75 revisions
digitreck Android SDK intends to simplify the usage of digitreck features like location repository, real-time tracking and places with a nice fluid API.
Supported Android SDK versions: 16+
Supported Google Play Services compatible version: 11.0.2+
The fastest and easiest way to use digitreck in your project is with Gradle.
- Add digitreck maven repository to repositories in project's build.gradle
apply plugin: 'com.android.application'
allprojects {
repositories {
jcenter()
maven {
url 'http://maven.digitreck.com/public'
}
}
}- Add digitreck-base dependency
compile 'com.google.android.gms:play-services-location:11.0.2'
compile 'com.digitreck.android:base:1.0.4'Integrate the SDK in Application class
- Initiate the SDK
OnSetupListener setupListener = new OnSetupListener() {
@Override
public void onReady(String device) {
// triggered on successful setup
}
@Override
public void onFailed(String error) {
// triggered on setup failed
}
};
@Override public void onCreate() {
super.onCreate();
SdkConfiguration sdkConfiguration = new SdkConfiguration.Builder(this)
.group(YOUR_GROUP_ID)
.callback(setupListener)
.environment(Environment.PROD) /* PROD or SANDBOX */
.mode(LocationMode.FUSED) /* FUSED or PASSIVE */
.build();
Digitreck.init(sdkConfiguration);
}- Terminate the SDK
Digitreck.terminate();Congratulations! You have successfully performed the basic digitreck integration and are ready to perform tasks like uploading location and tracking other devices.
- Starting Location updates
Digitreck.LocationApi.start(new OnLocationServiceEventListener() {
@Override
public void onPermissionRequired(String[] permissions) {
// triggered when application requires location permission
}
@Override
public void onLocationServiceRequired() {
// triggered when application requests to enable GPS
}
@Override
public void onStarted() {
// triggered when location service has started successfully
}
});- Stoping Location updates
Digitreck.LocationApi.stop();- Other utilities
Notify library when permission is granted
Digitreck.LocationApi.onPermissionGranted();Notify library when GPS is enabled
Digitreck.LocationApi.onLocationServiceEnabled();private LocationUpdateListener locationListener = new LocationUpdateListener() {
@Override
public void onLocationChanged(Location location) {
//triggered when location change is detected
}
};- Requesting Location Updates
Digitreck.LocationApi.subscribe(locationListener);- Cancel Location Updates
Digitreck.LocationApi.unsubscribe(locationListener);TrackListener trackListener = new TrackListener() {
@Override
public void onTrack(HashMap<String, GeoPoint> data) {
//triggered when new location data is received
}
};- Requesting for tracking
Digitreck.TrackApi.subscribe(trackListener, TRACKING_ID);- Cancel tracking
Digitreck.TrackApi.unsubscribe(trackListener);PlacesListener placesListener = new PlacesListener() {
@Override
public void onEnter(Place place) {
//when device reaches near some place.
}
@Override
public void onExit(Place place) {
//when device moves away from already reached place.
}
};- Requesting for Place Events
Digitreck.PlacesApi.subscribe(placesListener);- Cancel Place Events
Digitreck.PlacesApi.unsubscribe();