startForegroundService method
Future<MapxusMethodResponse>
startForegroundService({
- required String appId,
- required String secret,
- String notificationTitle = 'Mapxus Positioning',
- String notificationContent = 'Location tracking is active',
override
Starts the Android foreground service for background positioning.
This keeps positioning active even after the user closes the app. Events are delivered through the same events stream.
appId and secret are your Mapxus credentials.
notificationTitle and notificationContent customise the persistent notification.
Implementation
@override
Future<MapxusMethodResponse> startForegroundService({
required String appId,
required String secret,
String notificationTitle = 'Mapxus Positioning',
String notificationContent = 'Location tracking is active',
}) async {
try {
final result = await _channel.invokeMethod<Map<dynamic, dynamic>>(
'startForegroundService',
{
'appId': appId,
'secret': secret,
'notificationTitle': notificationTitle,
'notificationContent': notificationContent,
},
);
return MapxusMethodResponse.fromMap({
'success': result?['success'] ?? false,
'message': result?['message'] ?? 'Unknown error',
});
} catch (e) {
return MapxusMethodResponse.fromMap({
'success': false,
'message': e.toString(),
});
}
}