原理
添加角標(biāo)的原理就是發(fā)送一個(gè)Broadcast(廣播),在廣播的Intent中指定需要被添加角標(biāo)的應(yīng)用的packageName(包名),className(類(lèi)名),count(角標(biāo)數(shù)目)。當(dāng)然了,不同廠商的手機(jī)的角標(biāo)操作的Intent的action是不一樣的。
https://github.com/leolin310148/ShortcutBadger
可能會(huì)碰到如下兩個(gè)問(wèn)題:
http://blog.csdn.net/xx326664162/article/details/51083400
http://blog.csdn.net/xx326664162/article/details/51087827
使用方法
- Add mavenCentral to your build script.
repositories {
mavenCentral()
}
- Add dependencies for ShortcutBadger, it's available from maven now.
dependencies {
compile "me.leolin:ShortcutBadger:1.1.13@aar"
}
- Add the codes below:
int badgeCount = 1;
ShortcutBadger.applyCount(context, badgeCount); //for 1.1.4+
ShortcutBadger.with(getApplicationContext()).count(badgeCount); //for 1.1.3
- If you want to remove the badge
ShortcutBadger.removeCount(context); //for 1.1.4+
ShortcutBadger.with(getApplicationContext()).remove(); //for 1.1.3
or
ShortcutBadger.applyCount(context, 0); //for 1.1.4+
ShortcutBadger.with(getApplicationContext()).count(0); //for 1.1.3
Android系統(tǒng) 小米,三星,索尼手機(jī)發(fā)送桌面快鍵提醒數(shù)字圖標(biāo),在Android系統(tǒng)中,眾所周知不支持BadgeNumber,雖然第三方控件BadgeView可以實(shí)現(xiàn)應(yīng)用內(nèi)的數(shù)字提醒。
但對(duì)于系統(tǒng)的圖標(biāo),特別是app的logo圖標(biāo)很難實(shí)現(xiàn)數(shù)字標(biāo)志,即使是繪圖的方式不斷修改,但這種方式天生弊端,實(shí)用性很差。但幸運(yùn)的是,某些ROM廠商提供了私有的API,但也帶來(lái)了難度,API的不同意意味著代碼量的增加和兼容性問(wèn)題更加突出。

《Android群英傳》和《Android群英傳:神兵利器》的作者 徐宣生 也在自己的Github上建了一個(gè)項(xiàng)目:https://github.com/xuyisheng/ShortcutHelper ,挺有意思,里面還有號(hào)稱(chēng)“瘋狂模式”的為所有在手機(jī)桌面上的應(yīng)用加上99的角標(biāo)數(shù)的功能,當(dāng)然了,去除的代碼也有,不然處女座豈不是要暈了~
參考:
http://my.oschina.net/ososchina/blog/352286?p=1#comments
http://www.voidcn.com/blog/kongbaidepao/article/p-62251.html
http://www.eoeandroid.com/thread-557210-1-1.html