Badge analysis & how to Kill Virgo

Source: Internet
Author: User

Badge analysis

The so-called badge, originally an effect on iOS, but by Android copied more, also become the standard Android. The picture is not up, we all know.

Application icon display angle is actually implemented in the launcher, in fact, whether it is a corner or other shortcuts to the addition and deletion of the change, are required to launcher support, application in addition and deletion to find shortcuts and installation, uninstall, will issue corresponding broadcasts, through this broadcast, Launcher will make changes to the shortcut method.

Fortunately, Android native ROM launcher does not have the ability to add a corner tag to icon, because Android is designed to put all the message center in the notification notification bar, only the iOS such notification bar semi-disabled, will use the corner label. This thing, let obsessive-compulsive patients, completely unable to take care of themselves, daily fall in the clear Little red dot life.

Very tragic, Android AOSP code by the domestic major ROM manufacturers to change can not be self-reliant. Many of the modified ROMs can support this angular function, and even many third-party launcher provide this functionality. Its basic principle is also a big copy of the world, are listening to the broadcast to make shortcuts to modify, but the key is no Google pro-dad support, all the implementation is not unified, we do their own, there is no unified interface, resulting in a variety of fragmentation is very serious.

Now the principle is clear, the key is to find as many of these ROM, launcher change the icon of the broadcast.

In the investigation of the problem, I found Https://github.com/leolin310148/ShortcutBadger this library, a lot of places reference the library, but the library for a long time without maintenance, so I extracted some of the badge collected inside the method, And made a perfect, here to the author express thanks.

Various ROM angle Index analysis miui6&7 Badge

The following content is from the MUI Developer platform:

First, the basic introduction

1, the default situation

When the app sends a notification to the notification bar (without a progress bar and the user can delete it), the Desktop app icon will display 1. The app displays a number of corner marks corresponding to the number of notifications sent by the app in the notification bar, that is, how many corner labels are displayed to the notification bar.

2, notice can define the number of corners

For example, there are 5 unread messages, only one notification is displayed in the notification bar, but you want the corner label to show 5. You can add an indication when you send the notification.

The principle of modifying MIUI is to get Notification 's private property extranotification by reflection, but this extranotification is redefined in the MIUI system, This class is the Android.app.MiuiNotification class in the MIUI system, which has a private property messagecount, and we just change the messagecount value to show the change app Icon has a number of corners.

Second, the implementation of the Code

Third-party apps need to be called with reflection, reference code:

/** * Set MIUI's badge * * @param Context context * @param count Count */Private Static void SETBADGEOFMIUI(Context context,intCount) {LOG.D ("XYs","LAUNCHER:MIUI"); Notificationmanager Mnotificationmanager = (notificationmanager) context. Getsystemservice (context.notification    _service); Notification.builder Builder =NewNotification.builder (context). Setcontenttitle ("title"). Setcontenttext ("Text"). Setsmallicon (R.mipmap.ic_launcher); Notification Notification = Builder.build ();Try{Field field = Notification.getclass (). Getdeclaredfield ("Extranotification");        Object extranotification = field.get (notification); method = Extranotification.getclass (). Getdeclaredmethod ("Setmessagecount",int. Class);    Method.invoke (Extranotification, Count); }Catch(Exception e)    {E.printstacktrace (); } mnotificationmanager.notify (0, notification);}
Sony Badge

https://forsberg.ax/en/blog/android-notification-badge-app-icon-sony/

Samsung Badge Method One

Add a corner label to your app via Samsung Launcher's own broadcast:

/** * Set up Samsung's Badge * * @param Context context * @param count Count */Private Static void Setbadgeofsumsung(Context context,intCount) {//Get your current appString Launcherclassname = getlauncherclassname (context);if(Launcherclassname = =NULL) {return; } Intent Intent =NewIntent ("Android.intent.action.BADGE_COUNT_UPDATE"); Intent.putextra ("Badge_count", count); Intent.putextra ("Badge_count_package_name", Context.getpackagename ()); Intent.putextra ("Badge_count_class_name", launcherclassname); Context.sendbroadcast (intent);}

This method does not require any permissions, just need to know the app's package name and class name. Therefore, you can of course in the program to any other app set any number of corners, and no hint, yes, very rogue, who said not, of course, don't say I told you, you are Baidu. For example:

intent.putExtra("badge_count_package_name""com.tencent.mobileqq");    intent.putExtra("badge_count_class_name""com.tencent.mobileqq.activity.SplashActivity");

Replace the package name and the class name with QQ, and then you can do whatever you want.

Method Two

Https://github.com/shafty023/SamsungBadger

LG Badge

Samsung good friends, Samsung can use, LG almost all can use, even bugs are the same.

Huawei Emui Badge

Currently, Huawei's ROM only supports the addition of a corner mark to the built-in app, and Huawei itself does not provide the appropriate interface.

Cool Pie Badge

Simple rude, not supported. I like that kind of native.

ZUK ZUI Badge

Zuk as a very small number of mobile phone manufacturers, incredibly in the online official to give a detailed developer documentation, on this point, a lot of big companies should take a good beating their ears.

Because I really can not find Zuk test machine, so here to give Zuk developer documentation, you need to look at it:

Http://developer.zuk.com/detail/12

HTC Badge

HTC is declining, but somehow the first Android parasite, at least, is supported.

intent intentnotification = new  Intent ( "Com.htc.launcher.action.SET_NOTIFICATION" ); ComponentName localcomponentname = new  componentname (Context.getpackagename (), Ap Pinfoutil.getlauncherclassname (context)); Intentnotification.putextra (, localcomponentname.flattentoshortstring ()); Intentnotification.putextra ( "Com.htc.launcher.extra.COUNT" , COUNT); Context.sendbroadcast (intentnotification); Intent intentshortcut = new  Intent ( Span class= "hljs-string" > "Com.htc.launcher.action.UPDATE_SHORTCUT" ) Intentshortcut.putextra (" PackageName ", Context.getpackagename ()) Intentshortcut.putextra (, Count); Context.sendbroadcast (intentshortcut); 

The same principle is the use of radio, not explained.

Hammer

The hammer is unfortunately used by native launcher for modifications, only the system app has access to the corner label.

Nova Badge

Nova is a great launcher, and as a third-party launcher, its usage is very high (abroad, of course). The launcher, as the industry's conscience, provides content provider for external invocation. Like the Zuk phone, the conscience is greatly good, the code is as follows:

new ContentValues();contentValues.put("tag""/" +        AppInfoUtil.getLauncherClassName(context));contentValues.put("count", count);context.getContentResolver().insert(Uri.parse("content://com.teslacoilsw.notifier/unread_count"),        contentValues);
Some of the fun

We can do some interesting things when we know the principle of the generation angle of some ROM. In front of the LG Samsung Sony's ROM, it has been mentioned that the broadcast only need to send the package name and start the activity name can be given to any icon to add a corner label, so ... Look directly at the code:

/** * Bug use test, do not misuse * * @param View View */ Public void Madmode(View view) {Madmode ( About);}/** * Clear Bug Corner sign * * @param View View */ Public void Cleanmadmode(View view) {Madmode (0);}/** * Get package name and startup class name for all apps * * @param count Count */Private void Madmode(intCount) {Intent Intent =NewIntent (Intent.action_main,NULL);    Intent.addcategory (Intent.category_launcher); list<resolveinfo> list = Getpackagemanager (). Queryintentactivities (Intent, Packagemanager.get_activities ); for(inti =0; I < list.size ();        i++) {Activityinfo activityinfo = List.get (i). Activityinfo;        String activityname = activityinfo.name;        String PackageName = activityInfo.applicationInfo.packageName;    Badgeutil.setbadgeofmadmode (Getapplicationcontext (), Count, PackageName, activityname); }}

The very simple code is to find the activity with start intent through PM, then take out its package name and add the corner label by setting. Effect


OK, crazy, forced to die of obsessive-compulsive Virgo.

Do not abuse, this caused by all the problems, do not find me

Please do not mention the desktop background!!!

Badge analysis & how to Kill Virgo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.