Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
460 views
in Technique[技术] by (71.8m points)

android - Controlling the Alarm icon in status bar

This question relates to Android versions pre-Lollipop. For Lollipop API, check related question:


I would like to know how to turn on / off the system Alarm icon in the status bar as shown in this image:

Android system Alarm icon

From what I understand about the system, and what I've read in the past, it is controlled by the built in system alarm clock app. And 3rd party apps have no control over it on an unrooted device. There is no reason we should be able to control it.

However, Timely v1.2.7 controls this icon on my unrooted Galaxy Nexus v4.2.1, & Nexus 5 v4.4.2. So it is possible.

I wonder what the technique is to do this on an unrooted device. I suspect a hack or undocumented code but still interested if anyone can shed some light.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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, which has an answer on it:

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...