Shifts

Manage the driver online and offline states

Overview

A user is considered available/online only while he has an active (started) shift on Bringg Platform Cloud Services.
While being online the SDK automatically handles all the communication with Bringg Platform to update the local data.

The Bringg Driver SDK for Android exposes shift state management to enable the implementation to control when a user is online on Bringg Platform.

When a user is online the SDK will continuously communicate with Bringg Platform Cloud Services in the background to send, receive and monitor assigned tasks, location tracking, geofencing, ETA calculations and more.

Online state is persisted by the SDK and Bringg Platform Cloud Services and the SDK will automatically resume from the last state when initialized.

Bringg Platform allows the shift to be ended remotely (such as by a dispatcher or an api call), in such case the SDK will automatically become offline and notify the implementation using LiveData .

🚧

While online the SDK is continuously running in the background

This consumes network, GPS and other location monitoring resources from the mobile device.
Be sure to end the shift as soon as the user doesn't need to be connected to the Bringg Platform Cloud Services such as when the user has finished his work for the day.

Observe online state

Online state can be observed using a LiveData object obtained from DriverSdk:

DriverSdkProvider.driverSdk.data.online.observeForever { isOnline ->
    val navController = findNavController()
    if (isOnline) {
        Log.i(TAG,"user is online, DriverSdk is working in the background")
    } else {
        Log.i(TAG,"user is not online, DriverSdk is working in the background")
    }
}

Manage the user online state

Start Shift (Become online)

Start a driver's shift.

When a user has an active shift the DriverSdk is responsible for showing the foreground service notification to the user indicating that the app is active in the background.

DriverSdkProvider.driverSdk.shift.startShift(object : ResultCallback<ShiftStartResult> {
    override fun onResult(result: ShiftStartResult) {
        if (result.success) {
            Log.i(TAG,"user is online, DriverSdk is working in the background, DriverSdkProvider.driverSdk.data.online will post TRUE")
        } else {
            Log.i(TAG,"start shift request failed, error=${result.error}")
        }
    }
})

Parameters

callback

ResultCallback<StartShiftResult>

NOT NULLABLE

receive StartShiftResult model with the action result

StartShiftResult

model containing the start shift request result

Parameters

success

Boolean

NOT NULLABLE

is the user online and successfully connected to Bringg Platform Cloud Services.

When success=TRUE LiveData driverSdk.data.online will post TRUE value and DriverSdk will show foreground notification and become active in the background.

error

StartShiftResult.Error?

NULLABLE

In case of failure (success = FALSE)

this will indicate the reason for the failure.

actions

Collection<DriverActionItem>

NOT NULLABLE

Only populated when success = FALSE and error is ACTIONS_NOT_DISPLAYED or ACTIONS_REQUIRED

StartShiftResult Errors

REJECTED_BY_REMOTE

server returned error response

NOT_LOGGED_IN

see Authentication

NETWORK_ERROR

check device network state and try again

ALREADY_STARTED

shift is already started

HAS_ONGOING_SHIFT

user already has an ongoing shift

ANOTHER_DEVICE

user is already online on another device

DISTANCE_FROM_WORKPLACE

the user is not within an allowed distance from the workplace to start a shift

TIME_OF_DAY

the current time is either before or after the allowed shift start time

DISTANCE_AND_TIME

the user is not within an allowed distance from the workplace and the current time is either before or after the allowed shift start time

ACTIONS_NOT_DISPLAYED

shift actions has to be displayed before starting the shift

ACTIONS_REQUIRED

mandatory shift actions has to be taken before starting the shift

End Shift (Become offline)

End a driver's shift.

When a user shift has ended DriverSdk is responsible for hiding the foreground service notification and stopping all tracking and network communication.

DriverSdkProvider.driverSdk.shift.endShift(object : ResultCallback<ShiftEndResult> {
    override fun onResult(result: ShiftEndResult) {
        if (result.success) {
            Log.i(TAG,"user is offline, DriverSdk stopped all background processes, DriverSdkProvider.driverSdk.data.online will post FALSE")
        } else {
            Log.i(TAG,"end shift request failed, error=${result.error}")
        }
    }
})

Parameters

callback

ResultCallback<ShiftEndResult>

NOT NULLABLE

receive ShiftEndResult model with the action result

EndShiftResult

model containing the end shift request result

Parameters

success

Boolean

NOT NULLABLE

is the user offline and successfully disconnected from Bringg Platform Cloud Services.

When success=TRUE LiveData driverSdk.data.online will post FALSE value and DriverSdk will dismiss the foreground notification and close all background services.

error

EndShiftResult.Error?

NULLABLE

In case of failure (success = FALSE)

this will indicate the reason for the failure.

actions

Collection<DriverActionItem>

NOT NULLABLE

Only populated when success = FALSE and error is ACTIONS_NOT_DISPLAYED or ACTIONS_REQUIRED

EndShiftResult Errors

REJECTED_BY_REMOTE

server returned error response

NOT_LOGGED_IN

see Authenticaction

NETWORK_ERROR

can't communicate with Bringg Cloud Services, check device network state and try again

DEVICE_OFFLINE

check device network state and try again

DISTANCE_FROM_WORKPLACE

the user is not within an allowed distance from the workplace to end a shift

TIME_OF_DAY

the current time is either before or after the allowed shift end time

DISTANCE_AND_TIME

the user is not within an allowed distance from the workplace and the current time is either before or after the allowed shift end time

ACTIONS_NOT_DISPLAYED

shift actions has to be displayed before ending the shift

ACTIONS_REQUIRED

mandatory shift actions has to be taken before ending the shift


What’s Next