Mobility Insights
To learn about the Mobility Insights feature, check out this page.
Prerequisites
The Mobility Insights feature relies on additional library dependencies alongside the core SDK dependency. To start using this feature, you must first add these dependencies to you project.
Android
Open your app build.gradle file and add the event timeline dependency.
dependencies {
implementation(platform('com.sentiance:sdk-bom:<sentiance-version>'))
implementation('com.sentiance:sdk-event-timeline')
}Utilize the Event Timeline APIs
In this section, you can find examples of how to query the Sentiance SDK for historic timeline events (e.g. transports and stationaries), and how to register to receive timeline updates in your app, as new events are detected or existing ones are updated.
Query for Historic Events
You can query for past events in the user's timeline by utilizing the getTimelineEvents method.
The Sentiance SDK has the capacity to remember 9 weeks of events. It is recommended to store a copy of these events on your end, that way, you can store a much longer history. To properly collect events and store them in your own event store, check out the next section.
Subscribe for and Retrieve Event Timeline Updates
Checkout Real-time Listeners to read more about implementing the SDK's Listeners
To receive event updates, such as when a transport starts or ends, you can subscribe for event timeline updates.
The example below demonstrates a robust approach to collecting timeline events by combining an event update subscription with a query for updates since the last processed event. This ensures the logic remains resilient to interruptions or unexpected app terminations.
To get event timeline updates even when your app is in the background, place the following code inside your app's entrypoint index.js file. If you're only interested in these updates when your app is foregrounded, place this code inside the appropriate UI code instead.
Create a background.dart file under your project's lib folder with the following code:
Add the following code according to your target platform.
For iOS, add the following to your app delegate class:
For Android, add this code to your custom application class:
If you're calling other 3rd party plugin APIs inside your registerEventTimelineListener Dart function, then you need to register these plugins with the Sentiance SDK. See this for more details.
Last updated