If location permission is not granted by the user, Trip Analysis SDK will not work.
Activity Recognition Permission
If you want to enable the automatic trip detection mode, DriveKitTripAnalysis.activateAutoStart(true) must be called once the Activity Recognition permission is granted by the user. Read more.
For device running Android 10 and above, it's required to ask the user for activity recognition permission. Find below an example of how to ask the permission:
If activity recognition permission is not granted by the user, Trip Analysis component will not work.
Nearby Devices Permission
For devices running Android 12 and above, it's required to ask the user for Nearby Devices permission. Find below an example of how to ask Nearby Devices permission:
funcheckNearbyDevicesPermission(activity: Activity, requestCode : Int) {val isNearbyDevicesPermissionAuthorized =if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { ContextCompat.checkSelfPermission( activity, Manifest.permission.BLUETOOTH_SCAN ) == PackageManager.PERMISSION_GRANTED&& ContextCompat.checkSelfPermission( activity, Manifest.permission.BLUETOOTH_CONNECT ) == PackageManager.PERMISSION_GRANTED } else {true }if (!isNearbyDevicesPermissionAuthorized && Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { val shouldShowRationaleScan = shouldShowRequestPermissionRationale(activity, Manifest.permission.BLUETOOTH_SCAN)
val shouldShowRationaleConnect = shouldShowRequestPermissionRationale(activity, Manifest.permission.BLUETOOTH_CONNECT)
if (!shouldShowRationaleScan ||!shouldShowRationaleConnect) {// Display a message to explain why the permission is necessary } else { requestPermissions(activity, arrayOf(Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT), requestCode)
} }}
publicvoidcheckNearbyDevicesPermission(Activity activity,int requestCode) {boolean isNearbyDevicesPermissionAuthorized;if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.S) { isNearbyDevicesPermissionAuthorized =ContextCompat.checkSelfPermission( activity,Manifest.permission.BLUETOOTH_SCAN ) ==PackageManager.PERMISSION_GRANTED&&ContextCompat.checkSelfPermission( activity,Manifest.permission.BLUETOOTH_CONNECT ) ==PackageManager.PERMISSION_GRANTED; } else { isNearbyDevicesPermissionAuthorized =true; }if (!isNearbyDevicesPermissionAuthorized &&Build.VERSION.SDK_INT>=Build.VERSION_CODES.S) { final boolean shouldShowRationaleScan = shouldShowRequestPermissionRationale(activity, Manifest.permission.BLUETOOTH_SCAN);
final boolean shouldShowRationaleConnect = shouldShowRequestPermissionRationale(activity, Manifest.permission.BLUETOOTH_CONNECT);
if (!shouldShowRationaleScan ||!shouldShowRationaleConnect) {// Display a message to explain why the permission is necessary } else { requestPermissions(activity, new String[] { Manifest.permission.BLUETOOTH_SCAN, Manifest.permission.BLUETOOTH_CONNECT }, requestCode);
} }}
If Nearby Devices permission is not granted by the user, Trip Analysis component won't work correctly.
Notification Runtime Permission
For devices running Android 13 and above, it's required to ask the user for Notification runtime permission. If the permission is not granted, the user will not receive notifications.
Find below an example of how to ask the Notification permission:
First, declare the permission in your Manifest app file:
funcheckNotificationPermission(activity: Activity, requestCode: Int) {if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {val isNotificationPermissionAuthorized = ContextCompat.checkSelfPermission(activity, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTEDif (!isNotificationPermissionAuthorized) {if (ActivityCompat.shouldShowRequestPermissionRationale(activity, Manifest.permission.POST_NOTIFICATIONS)) {// Display a message to explain why the user need to grant the permission } else { ActivityCompat.requestPermissions(activity,arrayOf(Manifest.permission.POST_NOTIFICATIONS), requestCode) } } }}
publicvoidcheckNotificationPermission(Activity activity,int requestCode) {if (Build.VERSION.SDK_INT>=Build.VERSION_CODES.TIRAMISU) { boolean isNotificationPermissionAuthorized = ContextCompat.checkSelfPermission(activity, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED;
if (!isNotificationPermissionAuthorized) {if (ActivityCompat.shouldShowRequestPermissionRationale(activity,Manifest.permission.POST_NOTIFICATIONS)) {// Display a message to explain why the user need to grant the permission } else { ActivityCompat.requestPermissions(activity, new String[] { Manifest.permission.POST_NOTIFICATIONS }, requestCode);
} } }}
Google Play Services
Trip Analysis component requires Google Play Services Location 21.0.1 or above.
You can check if Play Services are available on the device with the following code:
It is required to ask the user to disable battery optimization for your app. Without battery optimization disabled, Trip Analysis SDK will not work properly.
The SDK usage is included into acceptable use cases for requesting or being on the Battery Optimizations exceptions whitelist. For more information you can read the Android developer documentation on this topic.
Firstly, define REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission in AndroidManifest.xml file of your application.
If battery optimization is enabled, trip recording will not work.
Some manufacturers add other battery optimizations. You can find tutorials on how to disable these battery optimizations for main Android device manufacturers here.