Skip to content

Driver's Alert

Alert events are assistant messages on the predicted path where the vehicle could drive along. They could help driver to prepare for upcoming driving conditionals, including but not limited to:

  • Warnings: safety camera, school zone, hazard spot, restrictions.
  • Highway info: Highway exits, rest areas and toll booths.
  • Traffic: incidents and flows.

Alert events could be notified with or without an active navigation session.

Step 1: Initialize a DriveSession. Please initialize SDK instance before acquiring it.

1
DriveSession driveSession = DriveSession.Factory.createInstance();
1
val driveSession : DriveSession = DriveSession.Factory.createInstance()

DriveSession will require FINE_LOCATION PERMISSION, If you are using customized Location Provider, We will provide API to initialize without default LocationManager.

Step 2: Implement a AlertEventListener interface and add it into the event hub. The Alert Event update can be received in the listener.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
AlertEventListener alertEventListener = new AlertEventListener() {
    @Override
    public void onAlertEventUpdate(@NonNull AlertEvent alertEvent) {
        if (alertEvent.getAheadAlertItems() != null) {
            for (AlertItem item : alertEvent.getAheadAlertItems()) {
                // check warnings and traffics on ahead path.
                // ...
            }
        }

        if (alertEvent.getBehindAlertItems() != null) {
            for (HighwayInfoItem item : alertEvent.getBehindAlertItems()) {
                // check warnings and traffics on passed path.
                // ...
            }
        }

        if (alertEvent.getAheadHighwayInfoItems() != null) {
            for (HighwayInfoItem item : alertEvent.getAheadHighwayInfoItems()) {
                // check highway info on ahead path.
                // ...
            }
        }

        if (alertEvent.getBehindHighwayInfoItems() != null) {
            for (HighwayInfoItem item : alertEvent.getBehindHighwayInfoItems()) {
                // check highway info on passed path.
                // ...
            }
        }
    }
}

driveSession.getEventHub().addAlertEventListener(alertEventListener);
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
val alertEventListener = object : AlertEventListener {
    override fun onAlertEventUpdated(AlertEvent alertEvent) {
        for (item in alertEvent.aheadAlertItems) {
            // check warnings and traffics on ahead path.
            // ...
        }

        for (item in alertEvent.behindAlertItems) {
            // check warnings and traffics on passed path.
            // ...
        }

        for (item in alertEvent.aheadHighwayInfoItems) {
            // check highway info on ahead path.
            // ...
        }

        for (item in alertEvent.behindHighwayInfoItems) {
            // check highway info on passed path.
            // ...
        }
    }
}

driveSession.eventHub.addAlertEventListener(alertEventListener)

Step 3: Enable alert event in drive session.

Enable alert event feature needs extra consumption and it's disabled by default.

1
driveSession.enableAlert(true);
1
driveSession.enableAlert(true)

Step 4: Disable alert event in drive session.

Users could disable alert event feature to save resource.

1
driveSession.enableAlert(false);
1
driveSession.enableAlert(false)

Step 5: Acquire detail information from AlertItem.

Usually, all categories of alert items use same base interface AlertItem to provide basic information including id, type and distance to vehicle. If the user wants to detail info for a specific alert item, it should down cast alert item to its child class.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
if (alertEvent.getAheadAlertItems() != null) {
    for (AlertItem item : alertEvent.getAheadAlertItems()) {
        switch (item.getType()) {
            case AlertType.SCHOOL_ZONE:
                ZoneAlert za = (ZoneAlert) (item);
                // handle zone-alert
                // ...
                break;
            default:
                // other alert type
                // ...
                break;
        }
    }
}
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
alertEvent.aheadAlertItems?.let {
    for (item in it) {
        when (item.type) {
            AlertType.SCHOOL_ZONE -> {
                val za = item as ZoneAlert
                // handle zone-alert
                // ...
            }
            else -> {
                // other alert type
                // ...
            }
        }
    }
}