1

In my android application I'm using the setAlarmClock() function to schedule an alarm. This alarm, as the android documentation states:

represents an alarm clock,

which means that the little alarm clock icon should be displayed on the notification bar indicating that there is an alarm pending.

My android phone has a MIUI overlay - it is a Xiaomi phone (SDK 29). Now, when I schedule the alarm:

alarmManager.setAlarmClock(
    new AlarmManager.AlarmClockInfo(calendar.getTimeInMillis(), alarmPendingIntent),
    alarmPendingIntent);

it works fine; it goes off at provided time, wakes the device up as expected etc. But the aformentioned icon indicator is missing - after setting the alarm the notification bar should (at least in theory) look like this:

Alarm icon displayed

but, obviously, it looks like this:

Alarm icon not displayed

For comparison, on another android device (SDK 24), this time with the EMUI overlay (Huawei), the setAlarmClock() function makes the alarm icon show up on the notification bar.

Now I don't know if the issue is MIUI specific or some settings are wrong. Is there a possible fix to my problem?

Update: From what I've seen, this issue relates to android devices operating under the MIUI other than mine as well. Seems like Xiaomi is using its own and what seems like more private API, to control the status bar events.

sweak
  • 1,369
  • 2
  • 6
  • 21

1 Answers1

0

As of Android 2.0, the system requires that apps that run constantly in the background, and that require a certain level of priority so that they don't get killed offhand (like music apps), put an Ongoing Notification. This was to prevent abuse of requesting this level of priority without letting the user know that it's occurring.

You can read about this here: http://developer.android.com/reference/android/app/Service.html#startForeground%28int,%20android.app.Notification%29

kalide
  • 89
  • 2
  • 6
  • 2
    Ok, but the alarm that I scheduled is not killed offhand. It is properly calling its pending intent - a broadcast receiver that calls a service that uses the mentioned `startForeground()` method to display the notification with an alarm sound. **The only problem** is that on scheduling the alarm (which works fine) there is **no alarm icon** on the notification bar indicating that the alarm has been set. – sweak Apr 14 '21 at 18:34