3

When I set an alarm with the build-in alarm clock application, there will be an icon on the right side of notification area. But it won't be there if I set an alarm with AlarmManager. Is there a way I can make that icon show?


I found it seems that alarm clock actually writes records to a ContentProvider rather than uses AlarmManager directly. I will give it a try tomorrow.

And it seems the provider is not intent to be used by other applications.

BlueWanderer
  • 2,671
  • 2
  • 21
  • 36

4 Answers4

4

Is there a way I can make that icon show?

That icon is for the Alarm Clock app that is part of the firmware. That icon will only appear if the user has an active Alarm Clock alarm. It cannot be directly manipulated by the Android SDK.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
2

This icon is part of the AlarmClock application NOT the android SDK. Android has a build-in (stock) AlarmClock application but many vendors (like Samsung) are replacing it with their own. So there isn't a safe way to display that particular icon from your application.

The best approach is to make your own icon since you are making an application that sets alarms and you want your users notified.

P.S. Here is the code of the Activity that displays the icon in the stock AlarmClock application as you can see in line 181 the drawable of the icon is R.drawable.stat_notify_alarm and not Android.R.drawable.stat_notify_alarm so you cannot use it.

Hope this helps...

ChD Computers
  • 3,135
  • 3
  • 23
  • 33
1

(cross-posted from self-answer on related question: Controlling the Alarm icon in status bar)


v5 Lollipop

Lollipop finally removed those private API features. This technique no longer works from v5.

I have posted a new question about Lollipop specifically, and hope to have answers there soon:

Pre-Lollipop

This is how it is done, using private api properties:

protected void setStatusBarIcon(boolean enabled)
{
    Intent alarmChanged = new Intent("android.intent.action.ALARM_CHANGED");
    alarmChanged.putExtra("alarmSet", enabled);
    sendBroadcast(alarmChanged);
}

Thanks to Andy Savage on this Google Groups thread:


Important note: as stated above, this uses private, undocumented properties. All the usual warnings apply around this, as pointed out by Dianne Hackborn on the same thread:

Note that when you see a raw string like that ("android.intent.action.ALARM_CHANGED" and "alarmSet"), warning bells should be going off in your head that this is using private APIs.

And indeed this is.

If you use this, don't be surprised if it breaks in the future on randomly doesn't work on some devices.

Community
  • 1
  • 1
Richard Le Mesurier
  • 29,432
  • 22
  • 140
  • 255
  • 1
    Yesterday I got a timely update where they are now able to show the alarm icon on the right side. Changelogs says "support for new alarm api to show the icon". Does somebody know which api is meant? Didn't find anything in the docs – maksim Feb 06 '15 at 10:30
  • @maksim thanks for pointing this out. I have posted a new question to try and find out about the new API: [Lollipop API for controlling the Alarm icon in status bar](http://stackoverflow.com/questions/28367822/lollipop-api-for-controlling-the-alarm-icon-in-status-bar) – Richard Le Mesurier Feb 06 '15 at 14:22
0

From what I understand from you're question, you're wondering how to make icons appear in the notification area.

You'll have to program that yourself. The documentation outlines this quite well.

http://developer.android.com/guide/topics/ui/notifiers/notifications.html

jlindenbaum
  • 1,891
  • 18
  • 28
  • Thanks. But actually I'm wondering how to make icons appear on the right side of the notification area. A custom alarm clock will look weird if can't set that icon as the build-in one does. – BlueWanderer May 13 '12 at 15:42
  • On the right side of what? If you're looking to align the image inside the status notification you can do that with a custom layout for the notification, which is described at the bottom of the page. – jlindenbaum May 13 '12 at 15:45
  • 1
    @jlindenbaum: I believe that the OP is referring to putting icons on the right side of the status bar. – CommonsWare May 13 '12 at 15:46