Skip to main content

Integrate the Fairmatic Android MAUI SDK

Binding Library for Fairmatic Android SDK

Installation

dotnet add package Fairmatic.Android --version 3.0.3

Prerequisites

  • The SDK supports the Android API 26 and above
  • dotnet SDK version 8.0.300 or above
  • Sign in to the Fairmatic dashboard to access your Fairmatic SDK Key.

Additional configurations

SupportedOSPlatformVersion

Update your *.csproj file to specify the supported minimum SDK version

<PropertyGroup>
<SupportedOSPlatformVersion>26</SupportedOSPlatformVersion>
</PropertyGroup>

AndroidManifest.xml

Based on your AndroidManifest.xml configuration, you might need to update allowBackup=true, dataExtractionRules, android:label & fullBackupContent

<manifest 
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:allowBackup="true"
tools:replace="android:label"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
...>
...
</application>
</manifest>

Sample backup rules

<data-extraction-rules>
<exclude domain="sharedpref" path="DriveKitPreferences.xml" />
<exclude domain="sharedpref" path="DriveKitEncryptedPreferences.xml" />
<exclude domain="sharedpref" path="DriveKitBackupPrefs.xml" />
<include domain="sharedpref" path="DriveKitBackup.xml" />
</data-extraction-rules>

Sample dataExtractionRules

<data-extraction-rules xmlns:tools="http://schemas.android.com/tools">
<cloud-backup>
<exclude domain="sharedpref" path="DriveKitPreferences.xml" tools:ignore="FullBackupContent" />
<exclude domain="sharedpref" path="DriveKitEncryptedPreferences.xml"
tools:ignore="FullBackupContent" />
<exclude domain="sharedpref" path="DriveKitBackupPrefs.xml" tools:ignore="FullBackupContent" />
<include domain="sharedpref" path="DriveKitBackup.xml" />
</cloud-backup>
<device-transfer>
<exclude domain="sharedpref" path="DriveKitPreferences.xml" tools:ignore="FullBackupContent" />
<exclude domain="sharedpref" path="DriveKitEncryptedPreferences.xml"
tools:ignore="FullBackupContent" />
<exclude domain="sharedpref" path="DriveKitBackupPrefs.xml" tools:ignore="FullBackupContent" />
<include domain="sharedpref" path="DriveKitBackup.xml" />
</device-transfer>
</data-extraction-rules>

Notification Icon Resource Id

With the new setup method, you need to provide a valid @DrawableResId in FairmaticTripNotification object. Failing to provide a valid resource id would result in bad notification icon for the Fairmatic SDK notifications. Follow these steps to generate resource id for your assets

  • Put the desired icon file (say fm_car.png) under Platforms/Android/Resources/drawable directory. It could be jpg, png, svg or Android vector drawable (xml) file. Note that it needs to be a monochrome image with snake_case filename
  • Build your project (dotnet build)
  • Get resource id using Resource.Drawable.fm_car (file name without extension)

Set up the Fairmatic SDK

To put the SDK into a “ready” state, you’ll first need to set up the Fairmatic SDK properly. This allows subsequent Insurance Period APIs to be called and the SDK to start actively capturing information. Replace the "YOUR_SDK_KEY" with the SDK key provided by the Fairmatic team.

FairmaticDriverAttributes fairmaticDriverAttributes = new FairmaticDriverAttributes(
firstName: "John",
lastName: "Doe",
email: "john.doe@example.com",
phoneNumber: "123-456-7890"
);

FairmaticConfiguration fairmaticConfiguration = new FairmaticConfiguration(
driverId: "your_driver_id",
sdkKey: "YOUR_SDK_KEY", // replace with your SDK key
driverAttributes: fairmaticDriverAttributes
);

FairmaticTripNotification fairmaticTripNotification = new FairmaticTripNotification(
"In Drive Notification", "You are now in drive mode.", Resource.Drawable.fm_car // your icon resource name
);

// Setup Fairmatic
Fairmatic.Instance.Setup(Android.App.Application.Context, fairmaticConfiguration, fairmaticTripNotification, fairmaticOperationCallback);
tip

This code should also be present in the flow when your driver logs in successfully into the app, and it should be called at every app launch with proper configuration. Failing to do so will result in errors in the trip APIs.

Call the insurance APIs

Insurance period 1

Start insurance period 1 when the driver starts the day and is waiting for a request. The tracking ID is a key that is used to uniquely identify the insurance trip.

Fairmatic.Instance.StartDriveWithPeriod1(Android.App.Application.Context, "trackingId1-maui", fairmaticOperationCallback);

Insurance period 2

Start insurance period 2 when the driver accepts the passenger's or the company's request.

Fairmatic.Instance.StartDriveWithPeriod2(Android.App.Application.Context, "trackingId2-maui", fairmaticOperationCallback);

Insurance period 3

Stop the insurance period when the driver ends the work day. Call stop period when the driver is no longer looking for a request.

Fairmatic.Instance.StartDriveWithPeriod3(Android.App.Application.Context, "trackingId3-maui", fairmaticOperationCallback);

Stopping the insurance period

Stop the insurance period when the driver ends the work day. Call stop period when the driver is no longer looking for a request.

Fairmatic.Instance.StopPeriod(Android.App.Application.Context, fairmaticOperationCallback);

Fairmatic SDK settings

Ensure you check for any errors and take appropriate actions in your app to resolve them, ensuring the Fairmatic SDK operates smoothly. Use the following code snippet to perform this check:

Fairmatic.Instance.GetFairmaticSettings(Android.App.Application.Context, new FairmaticSettingsCallbackImpl());	

Disable SDK [Optional step]

Call teardown API when the driver is no longer working with the application and logs out. This will completely disable the SDK on the application.

Fairmatic.Instance.Teardown(Android.App.Application.Context, fairmaticOperationCallback);