Android badge Add Corner labels to your app

Source: Internet
Author: User

Applying a corner mark is a feature of iOS, which is not supported by native Android. Perhaps it was because the IOS notification bar was a bit of a chicken (and of course it has improved a lot), and the Android notification bar is powerful? So it appears that one side relies on the digital angle mark, the party insists the powerful notice bar, in the daily use these two kind of interactive way each has the characteristic, does not have the vainly disobey feeling. But, uh, someone always wants to get some big news:

When a push is received and the app has no unread corner marks:
What kind of mobile phone---android! Android just can't!
Apple---me, this application even the corner mark is not supported! Delete.

So, the custom system or launcher of many mobile phone manufacturers are modeled after iOS to customize this feature. If you are in trouble, take a look at the two items on GitHub:

Https://github.com/leolin310148/ShortcutBadger

Https://github.com/xuyisheng/ShortcutHelper

I tried Shortcutbadger (1.1.13):

It was successfully measured in Huawei, Samsung, Xiaomi, Sony and Apex. But two questions were found:

1, some devices may throw an exception, causing the setup to fail. This is true on the Samsung Galaxy Note3 (Android5.0), where the exception was found to be thrown

This shows that the corner mark is implemented by sending a broadcast, and the Canresolvebroadcast method is to check if there is a receiver for that broadcast, and somehow some devices will not be found.

So I put down a code, changed the Canresolvebroadcast method directly, and then manually imported the AAR package into the project using the

2, Millet is more special, the number of his horn is directly determined by the number of notification bar. with the above method, the notification bar will appear with an empty notification at the same time. So I did a separate processing for the Millet corner label.

When you receive a push message creation notification, the number of corner labels is set into the notification by reflection, which is also the practice in the official documentation.

It is important to note that if you have several types of notifications, such as: There is a message, there is a new dynamic, etc., the message is an email notification of a notification, and the new dynamic is folded together (you have xx new dynamic unread), and even other not through the form of push notifications. I thought that in the setting of the corner mark to manually calculate the current number of all notifications, but after verification, we only need to care about the current received message, if it is collapsed to use the above method to manually set the quantity, the other does not need to deal with, a notification corresponding to the number of corners of the default is one, At the same time MIUI will automatically calculate the sum of the number of notifications to update the corner label.

Finally, if you are writing individually for a system or launcher, you can search directly for the appropriate methods of each home, but either way. Don't forget to add the appropriate badge permissions in Androidmanifest

Read the original

Android badge Add Corner labels to your app

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.