Android-Integration

Location:

Enable Location and Run-time permissions

To enable location, call the requestPermissions and requestLocationServices method. For Android 6.0 and above, calling this method will trigger a location permission popup that the user has to allow

Text

                                
                                    
  if(!GeoSpark.checkPermission(context)) {
     GeoSpark.requestPermission(this);
    } else if (!GeoSpark.checkLocationServices(context)) {
     GeoSpark.requestLocationServices(this);
    } else {
     GeoSpark.startTracking(context);
    }
    @Override
    public void onRequestPermissionsResult(int requestCode, String
    permissions[], int[] grantResults) {
     switch (requestCode) {
     case GeoSpark.REQUEST_CODE_PERMISSION:
     if (grantResults.length > 0
     && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
     if (ContextCompat.checkSelfPermission(context,

    android.Manifest.permission.ACCESS_FINE_LOCATION)
     == PackageManager.PERMISSION_GRANTED) {
     }
     }
     break;
     }
  }  
  @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent
    data) {
     super.onActivityResult(requestCode, resultCode, data);
     if (requestCode == GeoSpark.REQUEST_CODE_LOCATION_ENABLED) {
     }
  }          
                    
                               
                            

To start tracking the location, use the startTracking() method. You can keep SDK to track location, or turn it off if you want to stop tracking the user at any point of time using the stopTracking() method.

Text

                                
                                    
  GeoSpark.startTracking(this); 

                              
                            

Stop Location Tracking

You can stop tracking the user at any point of time using the stopTracking() method.

Text

                                
                                    
  GeoSpark.stopTracking(this);    
                            
                               
                            

Location listener

To listen for location in the background, create a class that extends GeoSparkReceiver. Then, register the receiver by adding a receiver element to the application element in your manifest:

Text

                                
                                    
 < application android:label="@string/app_name" ... >
 < receiver
 android:name=".MyGeoSparkReceiver"
 android:enabled="true"
 android:exported="false">
 < intent-filter >
 < action android:name="com.geospark.android.RECEIVED" / >
 < /intent-filter >
 < /receiver >
 < /application >     
                           
                               
                            

Trip:

Start Trip

Start trips in Geospark SDK, using startTrip() method.

Text

                                
                                    
  GeoSpark.startTrip(this, new GeoSparkTripCallBack() {
     @Override
     public void onSuccess(GeoSparkTrip geoSparkTrip) {
     geoSparkTrip.getTripId();
     geoSparkTrip.getTripStartedAt();
     }
     @Override
     public void onFailure(GeoSparkError geoSparkError) {
     geoSparkError.getErrorCode();
     geoSparkError.getErrorMessage();
     }
  });

                               
                            

End Trip

End trips in Geospark SDK, using endTrip() method.

Text

                                
                                    
  GeoSpark.endTrip(this, "tripId", new GeoSparkTripCallBack() {
     @Override
     public void onSuccess(GeoSparkTrip geoSparkTrip) {
     geoSparkTrip.getTripId();
     geoSparkTrip.getTripEndedAt();
     }
     @Override
     public void onFailure(GeoSparkError geoSparkError) {
     geoSparkError.getErrorCode();
     geoSparkError.getErrorMessage();
     }
  });                                
                               
                            

Active Trips

Get active trips in GeoSpark SDK, using activeTrips() method.

Text

                                
                                    
  GeoSpark.activeTrips(this, new GeoSparkTripsCallBack() {
     @Override
     public void onSuccess(GeoSparkTrips geoSparkTrips) {
     //List of GeoSparkTrips
     geoSparkTrips.getTripsId();
     }
     @Override
     public void onFailure(GeoSparkError geoSparkError) {
     geoSparkError.getErrorCode();
     geoSparkError.getErrorMessage();
     }
  });     
                           
                               
                            

Geofence:

Create Geofence

Create Geofence in GeoSpark SDK, using createGeofence() method.

Text

                                
                                    
GeoSpark.createGeofence(this, latitude, longitude, radius, expireInSeconds, new GeoSparkGeofenceCallBack() { @Override public void onSuccess(GeoSparkGeofence geoSparkGeofence) { geoSparkGeofence.getId(); geoSparkGeofence.getCreatedAt(); geoSparkGeofence.getExpiresAt(); geoSparkGeofence.getCoordinates(); geoSparkGeofence.getRadius(); } @Override public void onFailure(GeoSparkError geoSparkError) { geoSparkError.getErrorCode(); geoSparkError.getErrorMessage(); } });

Geofence List

Get created geofences in GeoSpark SDK, using geofenceList() method.

Text

                                
                                    
  GeoSpark.geofenceList(this, new GeoSparkGeofenceCallBack() {
     @Override
     public void onSuccess(GeoSparkGeofence geoSparkGeofence) {
     geoSparkGeofence.getGeofenceList();
     }
     @Override
     public void onFailure(GeoSparkError geoSparkError) {
     geoSparkError.getErrorCode();
     geoSparkError.getErrorMessage();
     }
  });