setAutoTripStartOnlyIfVehicleConnected method

Future<void> setAutoTripStartOnlyIfVehicleConnected(
  1. bool shouldAutoStartOnlyIfVehicleConnected
)

Enables or disables automatic trip start only if vehicle is connected.

Controls whether the SDK should automatically detect and start recording trips based on vehicle movement patterns if saved vehicle is connected. When enabled, the SDK will automatically begin trip recording when driving behavior is detected.

Parameters:

  • shouldAutoStartOnlyIfVehicleConnected: true to enable automatic trip start only if vehicle is connected, false to disable

Usage:

try {
  // Enable automatic trip start only if vehicle is connected
  await communicator.setAutoTripStartOnlyIfVehicleConnected(true);
  print('Automatic trip start enabled only if vehicle is connected');

  // Disable automatic trip start (manual start only)
  await communicator.setAutoTripStartOnlyIfVehicleConnected(false);
  print('Automatic trip start only if vehicle connected disabled - manual start required');
} catch (e) {
  print('Failed to change auto start setting: $e');
}

Throws:

  • Future.error("Unable to change trip auto start pref"): When setting update fails

Important Notes:

  • Setting persists across app sessions
  • When disabled, trips must be started manually using startTrip
  • Overrides the initial configuration from Kruzr360InitConfig
  • Changes take effect immediately for new trip detection

Use Cases:

  • User preference settings
  • Fleet management policies
  • Testing and debugging scenarios
  • False trip management optimization

Implementation

Future<void> setAutoTripStartOnlyIfVehicleConnected(
  bool shouldAutoStartOnlyIfVehicleConnected,
) async {
  try {
    await kruzr_comm.setAutoTripStartOnlyIfVehicleConnected(
      shouldAutoStartOnlyIfVehicleConnected,
    );
  } on Exception catch (e, stackTrace) {
    if (kDebugMode) {
      print("Error in setAutoTripStartOnlyIfVehicleConnected");
      print(stackTrace);
      print(e);
    }
    return Future.error(
      "Unable to change auto trip start only if vehicle connected pref",
    );
  }
  return;
}