1

There are lots Huawei icon badges related threads in SO, like How to show App Icon Badge Numbers on Huawei, and I have read the official document of Badges.

I do think the official documents are good enough, I just want to know how may we test it automatically?

For example, if one of the engineers in the team who mis-config the config the Badge-related SDK files, customers' Huawei phone would still able to push the notification, but the Badge number might not show.

I believe the image classification tech would help, like, we could test it automatically in the following way:

  1. Install the app and login the app by adb shell command + uiautomator
  2. Back the home screen in order to view the icon
  3. Push notifications from backend server.
  4. Screenshot the phone, and use some deep learning tech image classification to verify if there's Badge numbers on it.

It may not the best way to test it in these steps, I was wondering if maybe there is any native API to fetch the badge numbers?

alwaysday1
  • 1,683
  • 5
  • 20
  • 36
  • I'm not really sure, do you want to get the number of notification shown by the badge, or whether the badge is shown at all? In any case forget machine learning, it won't solve anything. – Nicolas Apr 29 '21 at 20:54
  • @Nicolas I just wanna to know whether the badge is shown at all, though it would be better if we could fetch the number shown by the badge. – alwaysday1 Apr 30 '21 at 01:06

1 Answers1

1

The best way to find this kind of information is to look for open source apps, like settings or launcher apps:

If you want to verify whether notification badges or on or off you can do:

Settings.Secure.getInt(context.contentResolver, "notification_badging")

This is even documented in the Settings class, but the setting name (Settings.Secure.NOTIFICATION_BADGING) is part of the hidden (internal) API. But still it works, at least it does for stock Android. For Huawei devices you'll have to test by yourself.

For obtaining the badge count, I don't know if it can be directly obtained. From the second link above, it seems you have to make a notification listener to count incoming notifications.

Nicolas
  • 6,611
  • 3
  • 29
  • 73
  • Some update on Huawei, I tried to use `int badging_flag = Settings.Secure.getInt(context.getContentResolver(), "notification_badging");`, it seems like always return `1`, no matter if there's number on the badge or not. – alwaysday1 May 07 '21 at 11:49
  • 1
    Oh I misunderstood then. It returns 1 if the setting to show badges is on, not whether a particular app has a badge on it. For this you'll probably need the notification listener (2nd link). – Nicolas May 07 '21 at 11:54