Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug(badge): set(...) only works after creating a notification. #3

Open
mahen23 opened this issue Jan 19, 2023 · 24 comments
Open

bug(badge): set(...) only works after creating a notification. #3

mahen23 opened this issue Jan 19, 2023 · 24 comments
Assignees
Labels

Comments

@mahen23
Copy link

mahen23 commented Jan 19, 2023

Plugin version:

    "@capawesome/capacitor-badge": "^2.0.2",

Platform(s):

generic #91~18.04.1-Ubuntu SMP Fri Jul 23 13:36:29 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

Current behavior:

Using Badge.set does not work, but works after creating a notification

Expected behavior:

Badge.set should work fine.

Steps to reproduce:

Badge.clear();
Badge.set({count: 10});
console.log("Badge Count: ", Badge.get()); // count is 0

Related code:

 Badge.clear();
    Badge.set({count: 10});
    console.log("Badge Count: ", Badge.get()); //count is 0

Other information:

Capacitor doctor:

💊 Capacitor Doctor 💊

Latest Dependencies:

@capacitor/cli: 4.6.2
@capacitor/core: 4.6.2
@capacitor/android: 4.6.2
@capacitor/ios: 4.6.2

Installed Dependencies:

@capacitor/cli: 4.4.0
@capacitor/ios: 4.4.0
@capacitor/core: 4.4.0
@capacitor/android: 4.4.0

[success] Android looking great! 👌

insert the output from `npx cap doctor` here
@robingenz
Copy link
Member

Can you provide a screen recording so that I better understand the problem?

@mahen23

This comment was marked as resolved.

@robingenz
Copy link
Member

robingenz commented Jan 19, 2023

You need to await the promise:

 function async setBadge() {
    console.log("Setting badge count to: ", this.badgeCount);
    await Badge.set({ count: this.badgeCount });
	const result = await Badge.get();
    console.log("Get Badge Count: ", result);
}

@robingenz robingenz self-assigned this Jan 19, 2023
@felipenunesdev
Copy link

I'm facing the same problem in Android.

I've got this reponse from plugin in Chrome console:

{ "callbackId": "57652480", "pluginId": "Badge", "methodName": "set", "options": { "count": 2 } }

But the icon badge is not showing.

@robingenz
Copy link
Member

robingenz commented Jan 19, 2023

@felipenunesdev The app needs to be installed as PWA.

Edited: I updated the docs.

@felipenunesdev
Copy link

felipenunesdev commented Jan 19, 2023

@robingenz Thanks for your reply!

Actually I'm using a native app. In IOS it works like a charm, the icon badge shows the correct counter, but in Android the badge is not showing.

@felipenunesdev
Copy link

@robingenz the Badge.get() method returns the correct counter value. Other apps I have installed on my phone, shows the icon badge correctly. So I assume that the android launch version is not the problem.

@robingenz
Copy link
Member

@felipenunesdev Please have a look at the documentation:

On Android not all launchers support badges. This plugin uses ShortcutBadger. All supported launchers are listed there.

Not all Android launcher are supported. Please have a look at ShortcutBadger and check if your device is supported.

If you have more questions, please create a new issue.

@mahen23

This comment was marked as resolved.

@robingenz
Copy link
Member

@mahen23 Please provide a Minimal, Reproducible Example (see How to create a Minimal, Reproducible Example) so I can debug the issue.

@mahen23

This comment was marked as resolved.

@robingenz
Copy link
Member

@mahen23 Can you please publish the example as GitHub repo?

@mahen23

This comment was marked as resolved.

@robingenz
Copy link
Member

Just create a normal GitHub repository and push all files:

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/mahen23/YOUR-REPO.git
git push -u origin main

@mahen23

This comment was marked as resolved.

@robingenz
Copy link
Member

Just create a normal GitHub repository and push all files:

git init
git add .
git commit -m "first commit"
git branch -M main
git remote add origin https://github.com/mahen23/YOUR-REPO.git
git push -u origin main

remote: Support for password authentication was removed on August 13, 2021. remote: Please see docs.github.com/en/get-started/getting-started-with-git/about-remote-repositories#cloning-with-https-urls for information on currently recommended modes of authentication. fatal: Authentication failed for 'mahen23/badgeBug.git'

See https://stackoverflow.com/a/68781050/6731412

@mahen23

This comment was marked as resolved.

@robingenz
Copy link
Member

You should only pass integers as count.
getRandomArbitrary also returns comma values:

$ Math.random() * (99 - 10) + 10
31.30685279633496 

Besides that, please let me know if this demo works for you: https://capacitor-plugin-demo-robingenz.vercel.app/badge

@mahen23

This comment was marked as resolved.

@robingenz
Copy link
Member

It makes not sense to test a demo link since the issue i'm having is when i build an APK.

This is the first time you have referred to Android. You have specified
generic #91~18.04.1-Ubuntu SMP Fri Jul 23 13:36:29 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux as the platform related to the bug.
For this reason, I assumed that the problem occurs in the browser.

I will take another look soon.

@robingenz robingenz transferred this issue from capawesome-team/capacitor-badge Apr 1, 2023
@robingenz robingenz changed the title bug: Badge.set does not work but work after creating a notification. bug(badge): Badge.set does not work but work after creating a notification. Apr 1, 2023
@dtarnawsky
Copy link

Hey @robingenz, I've created a sample Capacitor app here: https://github.com/dtarnawsky/cs-badge.

The problem appears to be Android specific and requires you to have sent at least one notification to the app for the badge to appear. The sample app has a button to send a local notification to the app in order for the badge to begin showing.

This may be a requirement of Android and it appears that the Cordova plugin cordova-plugin-badge suffers the same issue..

@robingenz
Copy link
Member

@dtarnawsky Great, thanks for pointing this out!
I found the Android documentation for this: https://developer.android.com/develop/ui/views/notifications/badges
The question is whether you can get this to work without showing a notification in the status bar. I'll have to take a closer look.

@robingenz robingenz added bug/fix Something isn't working and removed needs: triage labels Jun 23, 2023
@robingenz robingenz changed the title bug(badge): Badge.set does not work but work after creating a notification. bug(badge): set(...) only works after creating a notification. Dec 8, 2023
@robingenz
Copy link
Member

I set a bounty of $50 to solve the issue. I am looking for a clean solution, not a workaround. There is no guarantee that a solution exists.
Let me know if anyone wants to work on this.

@Eraldo
Copy link

Eraldo commented May 10, 2024

In case a notification is needed...
How about using a silent (aka data/remote) notification as a trigger to refresh the badge count? 🤷‍♂️

FYI: Just tossing an idea, didn't look at the details (yet). 😊

@robingenz robingenz removed the Fund label May 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

5 participants