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.

                                                                  
  if(!GeoSpark.checkPermission(this)) {
     GeoSpark.requestPermission(this);
  } else if (!GeoSpark.checkLocationServices(this)) {
     GeoSpark.requestLocationServices(this);
  } else {
     GeoSpark.startTracking(this);
  }
  @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(this,
            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.

                                                                    
 GeoSpark.startTracking(this);
                              
                            

Stop Location Tracking

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

                                                                  
 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.

Your receiver should implement the following:

                                                  
  public class MyGeoSparkReceiver extends GeoSparkReceiver {
         @Override
         public void onLocationUpdated(Context context, Location location,
                GeoSparkUser geoSparkUser, String activity){
                  // do something with context, location, user, Activity recognition
                }
    }
                           
                               
                            
                                
     <application>
        ...

        <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.

                                                                  
  GeoSpark.startTrip(TripActivity.this, "Description", 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.

                                                                  
  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.

                                
  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.

Make sure radius should be (50 -1000 meters) and set expiry time less than 24hrs.

                                
  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.

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

Delete Geofence

Delete Geofence in GeoSpark SDK, using deleteGeofence() method.

                                
  GeoSpark.deleteGeofence(this, "GeofenceId", new GeoSparkGeofenceCallBack()
  {
      @Override
      public void onSuccess(GeoSparkGeofence geoSparkGeofence) {
          geoSparkGeofence.getId();
          geoSparkGeofence.getMessage();
      }
      @Override
      public void onFailure(GeoSparkError geoSparkError) {
          geoSparkError.getErrorCode();
          geoSparkError.getErrorMessage();
      }
  });  
                              
                               
                            

User:

Update user Description

This will help to add a description to the user so that it is easier for you to identify your users, while tracking them in SDK. And GeoSpark SDKs provide you with the option to modify the description any time for a user. This can help you easily identify users on dashboard simply via the description.

                                
   GeoSpark.setDescription(this, "User Description", new GeoSparkCallBack() {
      @Override
      public void onSuccess(GeoSparkUser geoSparkUser) {
           geoSparkUser.getUserId();
      }

      @Override
      public void onFailure(GeoSparkError geoSparkError) {
          geoSparkError.getErrorCode();
          geoSparkError.getErrorMessage();
      }
  });