Open eirikwah opened 6 years ago
I have now submitted a pull request, #268, as my suggestion to how to fix this.
Just a clarification: On Samsung Galaxy S8 with Android 8.0, badges are still supported, but not by the same API as before, and it behaves differently.
Users can configure the "app icon badges" in the "Home screen settings". Users can choose to turn off badges, to show them without number, or show them with a number. This is a global setting for all apps, and app developers (such as us users of ShortcutBadger) can not override this.
In addition, badges can be disabled per app in the app settings.
Badges are only shown while there are visible notifications for the app. The number shown (if enabled by the user) is either the number of visible notifications, or the value set in the notification API method NotificationCompat.Builder.setNumber(int)
when creating the notification.
And to be clear: In my opinion, I don't think this new way of adding app icon badges should be a part of the ShortcutBadger API. When creating notifications, app developers should always call NotificationCompat.Builder.setNumber(int)
regardless. So ShortcutBadger can co-exist, and take effect on the still supported devices/Android versions.
@eirikwah i have a same problem. But i can't understand how you solve this. Please help me. Thank you
@canberkcakmak, you can see my suggested fix at the pull request #268. However, if you do not want to build a fork of ShortcutBadger, the fix is simply this wrapper code:
public boolean isBadgeCounterSupported() {
// Workaround for bug in ShortcutBadger in version 1.1.19, registered as
// https://github.com/leolin310148/ShortcutBadger/issues/266
if (Build.MANUFACTURER.equalsIgnoreCase("Samsung") && Build.VERSION.SDK_INT >= 26) {
Log.d("LOG_TAG", "Launcher icon badge (ShortcutBadger) is not supported on Samsung devices running Android 8 (or newer).");
return false;
}
return ShortcutBadger.isBadgeCounterSupported(context);
}
As for applying badges from your notifications, see the Android documentation, and note the section "Set custom notification count".
I don't have a Samsung device to test this, but I have to ask(Running a Nexus right now).
Will Nova Launcher(with Tesla unread) now not work on Samsung Oreo devices with this update?
I need to read more of the code but I'm assuming the answer is yes it works fine.
EDIT: I support this assuming it doesn't break Nova Launcher(and other install able launchers).
I don't have a Samsung device to test this, but I have to ask(Running a Nexus right now).
Will Nova Launcher(with Tesla unread) now not work on Samsung Oreo devices with this update?
I need to read more of the code but I'm assuming the answer is yes it works fine.
I do have a Samsung Galaxy S8 running Oreo, but I don't want to buy "Nova Launcher Prime" to test badges. I did test "Nova Launcher" (the free version), and this does not support badges on Samsung Galaxy S8 running Oreo. (I did the testing without the pull request #268 applied).
@eirikwah for Android 8, if the app has active notifications, there will be count on the launch icon. Will your fix just replace that count with your own. Or you do combine them together?
Update: It looks like the new badge will replace the original one by the system.
One alternative way is to create a low importance notification channel and set the setShowBadge(true);
, and then set the badge number on Notification builder with setNumber(int);
and show it when the app starts.
In this way a small notification always will be visible in the notification panel and when user dismiss it, the badge will be gone.
@eirikwah so what are users of Ionic 3/4 (inherently using https://github.com/katzer/cordova-plugin-badge plugin) supposed to do because they don't have a choice to just use setNumber()? Do we just need to wait for an update to ShortcutBadger? But you say it shouldn't even be a part of the ShortcutBadger API... This is a pressing issue right now for Ionic developers deploying to the newest Android versions in the market.
@eirikwah so what are users of Ionic 3/4 (inherently using https://github.com/katzer/cordova-plugin-badge plugin) supposed to do because they don't have a choice to just use setNumber()? Do we just need to wait for an update to ShortcutBadger? But you say it shouldn't even be a part of the ShortcutBadger API... This is a pressing issue right now for Ionic developers deploying to the newest Android versions in the market.
Hi, @Harmonickey. I am not familiar with Cordova nor Ionic, so this is a generic answer:
It seems that @leolin310148 or other contributors have not had the time to update this project in a while. I myself have not forked this project and created any new release, as I did find a workaround that worked for my project (see my previous comments).
However, is not a big problem that the fix is not merged into the main branch and released, as this is open source. :-) I suggest that you fork this project (feel free to include my pull request and/or code from the previous comments on this issue). Then you can include these changes in Cordova by following the guide they have written at https://github.com/katzer/cordova-plugin-badge#contributing .
Sorry for (probably) not giving you the answer you were looking for. I hope things work out for your project.
@eirikwah no worries, I appreciate the thoughtful response. I give your suggestions a try.
@eirikwah If all notifications are received from FCM cloud messaging, is it possible to reset the badge count to 0 locally upon opening the app without clearing notifications from the notification bar?
Tested on Samsung Galaxy S8 running Android 8.0 (Oreo).
Calling
ShortcutBadger.isBadgeCounterSupported(context)
returns true, but setting the badge has no effect. (This worked correctly before updating from Android 7.1 to Android 8.0.)It seems that the Samsung launcher on Android 8.0 rather uses the normal Android 8 function for badges instead (coupling it to active notifications).
Data from "IsBadgeWorking?":