capawesome-team / capacitor-badge

⚡️ Capacitor plugin to access and update the badge number of the app icon.
https://capawesome.io/plugins/badge/
MIT License
73 stars 4 forks source link

The badge does not work on latest Samsung #25

Closed happymago closed 2 years ago

happymago commented 2 years ago

Plugin version:

isSupported() method returns false. When digging into it more, I have found the shortcutBadger this plugin uses is not maintained anymore. And there is still this open issue https://github.com/leolin310148/ShortcutBadger/issues/266. It seems Android has come up with its own supported badge/notification since android 8. I wonder how everyone else is using this plugin?

Platform(s):

latest samsung latest pixel

Current behavior:

isSupported return false

Expected behavior:

isSupported return true

Steps to reproduce:

Related code:

insert short code snippets here

Other information:

Capacitor doctor:

insert the output from `npx cap doctor` here
robingenz commented 2 years ago

Hi @happymago, thank you for your request. I'll look at using Android's own badge setting interface to replace or extend ShortcutBadger once I have a little more time. I will get back to you.

drtomato commented 2 years ago

Hi @robingenz,

I use your plugin on IOS, where it works excellently! However, I am also migrating to Android and unfortunately here it doesn't work. I have tried to run both my app as well as the Capacitor plugin demo on an upgraded Samsung Galaxy S4 running LineageOS and a Samsung Galaxy S10e running Android 11. It seems that the badge settings are picked up properly inside the plugin, the problem is that the actual badge never appears on the screen. As happymago commented above, the problem seems to be inside ShortcutBadger. I can add more info if needed but if you plan to replace ShortcutBadger with Android's own interface maybe that isn't necessary. Anyway, your efforts are appreciated :)

robingenz commented 2 years ago

So I've been looking into this. First of all: I have two Android devices to test here: A Samsung Galaxy S4 (Android 5) and a OnePlus 7T (Android 11).

On the Samsung Galaxy S4 this plugin works, because this Samsung OS version is supported by ShortcutBadger. On the OnePlus 7T, the plugin does not work.

Android supports so-called "Notification Badges" since Android 8.0 (see here). These appear when an app has an active notification. I could not find any other way to display badges. If I have missed a possibility and someone has experience with it, I would be very grateful for any advice. Since these badges are thus dependent on the notifications of an app and Capacitor already offers a very good official plugin for this, I recommend using the Local Notification plugin if ShortcutBadger does not support the device.

Here is some sample code:

import { LocalNotifications } from '@capacitor/local-notifications';
import { Badge } from '@robingenz/capacitor-badge';

const set = async (count: number) => {
  const { isSupported } = await Badge.isSupported();
    if (isSupported) {
      await Badge.set({ count });
    } else {
      await LocalNotifications.schedule({
        notifications: [
          {
            id: 1,
            title: 'My Title',
            body: 'My Body',
          },
        ],
      });
    }
};

From my point of view, it is outside the scope of this plugin to support local notifications on Android. App icon badges are simply not a standalone feature on Android but a side effect of notifications.

I hope you can understand my point of view. I will turn this issue into a discussion so that we can gather other opinions and suggestions there as well.