Permissions
You first need to ask user's to allow the permissions below:
android.Manifest.permission.ACCESS_FINE_LOCATION,
android.Manifest.permission.ACCESS_BACKGROUND_LOCATION
Get off alerts enable/disable state for a trip
You can use GetOffAlertCache
to save get off alerts feature enable/disable state (or you can use your own) by your trip identifier.
Initialize class with application context
GetOffAlertCache.INSTANCE.init(applicationContext);
Set get off alert state for a trip
fun setTripAlertOnState(tripUuid: String, onState: Boolean)
Parameters
Name | Type | Required | Description |
---|---|---|---|
tripUuid | String | Yes | Your trip unique identifier |
onState | Boolean | Yes | enable/disable state |
Sample
GetOffAlertCache.setTripAlertOnState("your_trip_identifier", true)
Get get off alert state for a trip
fun isTripAlertStateOn(tripUuid: String): Boolean
Parameters
Name | Type | Required | Description |
---|---|---|---|
tripUuid | String | Yes | Your trip unique identifier |
Response
Boolean - the enable/disable state of get off alert for the specified trip
GeoLocation
This class handles the creation and removal of geofences for the trip segments when alerts are enabled
Add receiver on your project's Manifest.xml
<receiver
android:name=".routing.GeofenceBroadcastReceiver"
android:enabled="true"
android:exported="true">
<intent-filter>
<action android:name="com.skedgo.tripkit.routing.GeofenceBroadcastReceiver.ACTION_GEOFENCE_EVENT" />
</intent-filter>
</receiver>
Initialize class with application context
GeoLocation.INSTANCE.init(applicationContext)
GeoLocation.init(applicationContext)
Create Geofences using Geofence
from TripSegment
fun createGeoFences(geofences: List<Geofence>)
Parameters
Name | Type | Required |
---|---|---|
geofences | List<Geofence > |
Yes |
Sample
trip.segments?.mapNotNull { it.geofences }?.flatten()?.let { geofences -> GeoLocation.createGeoFences( geofences.map { geofence -> geofence.computeAndSetTimeline(trip.endDateTime.millis) geofence } ) }
Clear geofences
fun clearGeofences()
Alert for trip start
Add receiver on your project's Manifest.xml
<receiver
android:name=".routing.TripAlarmBroadcastReceiver"
android:enabled="true"
android:exported="true"/>
When get off alert is enabled for your trip, create an AlarmManager
instance using your Trip
's start segment
trip.segments.minByOrNull { it.startTimeInSecs }?.let { startSegment ->
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
val startSegmentStartTimeInSecs = startSegment.startTimeInSecs
val alarmIntent = Intent(context, TripAlarmBroadcastReceiver::class.java)
alarmIntent.putExtra(TripAlarmBroadcastReceiver.ACTION_START_TRIP_EVENT, true)
alarmIntent.putExtra(TripAlarmBroadcastReceiver.EXTRA_START_TRIP_EVENT_TRIP, Gson().toJson(trip))
var pendingIntent = PendingIntent.getBroadcast(context, 0, alarmIntent, 0)
}
then set the alarm trigger by time in milliseconds you want before the start of your Trip
's start segment
alarmManager.set(
AlarmManager.RTC_WAKEUP,
(TimeUnit.SECONDS.toMillis(startSegmentStartTimeInSecs) - TimeUnit.MINUTES.toMillis(5)),
pendingIntent
)