Other alarms
The Maps SDK for Android provides advanced notification capabilities, enabling users to receive alerts for significant environmental changes. This includes notifications for entering and exiting tunnels, as well as transitions between day and night, based on the user's current location and time of year.
Get notified when entering and exiting tunnels
This snippet below demonstrates how to set up notifications for entering and exiting tunnels using the AlarmListener:
- Kotlin
- Java
val alarmListener = AlarmListener.create {
onTunnelEntered {
Log.d("TunnelAlarm", "Tunnel entered")
// Update UI for tunnel mode (e.g., switch to night theme)
}
onTunnelLeft {
Log.d("TunnelAlarm", "Tunnel left")
// Update UI for normal mode (e.g., switch back to day theme)
}
}
AlarmListener alarmListener = AlarmListener.create(
() -> {
Log.d("TunnelAlarm", "Tunnel entered");
// Update UI for tunnel mode (e.g., switch to night theme)
},
() -> {
Log.d("TunnelAlarm", "Tunnel left");
// Update UI for normal mode (e.g., switch back to day theme)
}
);
Get notified when transitioning between day and night
The Maps SDK for Android offers functionality to notify users when their location transitions between day and night, based on the geographical region and the corresponding seasonal changes:
- Kotlin
- Java
val alarmListener = AlarmListener.create {
onEnterDayMode {
Log.d("DayNightAlarm", "Day mode entered")
// Update UI for day mode (e.g., light theme)
}
onEnterNightMode {
Log.d("DayNightAlarm", "Night mode entered")
// Update UI for night mode (e.g., dark theme)
}
}
AlarmListener alarmListener = AlarmListener.create(
() -> {
Log.d("DayNightAlarm", "Day mode entered");
// Update UI for day mode (e.g., light theme)
},
() -> {
Log.d("DayNightAlarm", "Night mode entered");
// Update UI for night mode (e.g., dark theme)
}
);