Skip to content
This repository has been archived by the owner on Sep 4, 2020. It is now read-only.

setApplicationIconBadgeNumber not working on Android but firing success function #1560

Closed
ofog opened this issue Feb 1, 2017 · 53 comments
Closed

Comments

@ofog
Copy link

ofog commented Feb 1, 2017

Expected Behaviour

setApplicationIconBadgeNumber to update the badge count on both Android and iOS.

Actual Behaviour

setApplicationIconBadgeNumber does not update the badge count, but fires the success callback on android. iOS works. I have downloaded isBadgeWorking which does does update the badge count

Reproduce Scenario (including but not limited to)

Add plugin, run code through remove devices in chrome

window.PushNotification = PushNotification.init({
  android: {
    senderID: "xxx",
    icon: 'truck_transparent'
  },
  ios: {
    alert: "true",
    badge: "true",
    sound: "true",
    "categories": {
    }
  },
  windows: {}
});

window.PushNotification.setApplicationIconBadgeNumber(function () {
            console.log("Updated badge");
          }, function () {
            console.log("Failed to update badge");
          }, 2);

Steps to Reproduce

Platform and Version (eg. Android 5.0 or iOS 9.2.1)

Android 6.0.1

(Android) What device vendor (e.g. Samsung, HTC, Sony...)

Sony E6653

Cordova CLI version and cordova platform version

cordova: 6.5.0
cordova platform version android: android 6.1.2

Plugin version

cordova plugin version:   1.9.2

Sample Push Data Payload

NA

Sample Code that illustrates the problem

See above.

Logs taken while reproducing problem

02-01 11:58:22.958 478-690/com.my.app V/PushPlugin: execute: action=init
02-01 11:58:22.964 478-691/com.my.app V/PushPlugin: execute: data=[{"android":{"senderID":"XXXXX","icon":"transparent"},"ios":{"alert":"true","badge":"true","sound":"true","categories":{}}},"windows":{}}]

02-01 11:58:23.065 478-691/com.my.app V/PushPlugin: execute: jo={"senderID":"1096839433110","icon":"truck_transparent"}
02-01 11:58:23.066 478-691/com.my.app V/PushPlugin: execute: senderID=1096839433110
02-01 11:58:23.075 478-691/com.my.app V/PushPlugin: onRegistered: {"registrationId”:”XXXXX”}
02-01 11:58:23.075 478-691/com.my.app D/PushPlugin: no iconColor option

02-01 11:58:24.347 478-691/com.my.app V/PushPlugin: setApplicationIconBadgeNumber: data=[{"badge":2}]

02-01 11:58:24.567 478-478/com.my.app D/SystemWebChromeClient: file:///android_asset/www/assets/myapp.js: Line 6490 : Updated badge
02-01 11:58:24.567 478-478/com.my.app I/chromium: [INFO:CONSOLE(6490)] "Updated badge", source: file:///android_asset/www/assets/myapp.js (6490)

@macdonst
Copy link
Member

macdonst commented Feb 1, 2017

@oliverfogden I would not code it the way you are coding it as you could be messing up the value of PushNotification. Try this instead:

window.push = PushNotification.init({
  android: {
    senderID: "xxx",
    icon: 'truck_transparent'
  },
  ios: {
    alert: "true",
    badge: "true",
    sound: "true",
    "categories": {
    }
  },
  windows: {}
});

window.push.setApplicationIconBadgeNumber(function () {
            console.log("Updated badge");
          }, function () {
            console.log("Failed to update badge");
          }, 2);

@ofog
Copy link
Author

ofog commented Feb 1, 2017

@macdonst thats a good heads up, the code was slightly different inside the app but was changed for the example.

Running the code you have noted above results in the same symptoms: The success function fires but the badge is not updated.

@macdonst
Copy link
Member

macdonst commented Feb 1, 2017

@oliverfogden that's cool. Just wanted to eliminate the potential obvious solution first. So this is:

  • on Android
  • ShortcutBadger supports the Sony E6653
  • you've used their test app to verify

@ofog
Copy link
Author

ofog commented Feb 1, 2017

@macdonst correct on all of the above. I'm fairly certain it was working on my Sony before upgrading it to 6, it was 5.1.1 before. As expected, the same code works in iOS 10.1.1

@macdonst
Copy link
Member

macdonst commented Feb 1, 2017

@oliverfogden ah, so when you upgraded from Android 5.1.1 to Android 6 it stopped working? But their test app still works with Android 6?

@ofog
Copy link
Author

ofog commented Feb 1, 2017

@macdonst yes it seems to be the case, I can't downgrade so I can't double check but I'm fairly certain. I have removed and re-installed the app just in case, but no change.

The test app works on Android 6 without any problems.

@macdonst
Copy link
Member

macdonst commented Feb 1, 2017

@oliverfogden so weird considering I use ShortcutBadger to set the badge. I think you should open an issue on SB and refer to this one.

@ofog
Copy link
Author

ofog commented Feb 1, 2017

@macdonst sure can do, as the IsBadgeWorking app seems to work, which runs ShortcutBadget 1.1.11 (which I think this plugin also uses?) and works, I'm afraid they are going to send me back here!

@macdonst
Copy link
Member

macdonst commented Feb 1, 2017

@oliverfogden yeah, SB says to run IsBadgeWorking first. See what they say and we can proceed. Sadly, I don't have a device that I can reproduce this on.

@ofog
Copy link
Author

ofog commented Feb 3, 2017

@macdonst the recommendation from ShortcutBadger seems to be to update ShortcutBadger...

macdonst added a commit that referenced this issue Feb 3, 2017
@macdonst
Copy link
Member

macdonst commented Feb 3, 2017

@oliverfogden apparently they released 1.1.12 four hours ago. I just upgraded the dependency. Can you try it and see if it fixes your issue? Just install directly from master:

cordova plugin add https://github.com/phonegap/phonegap-plugin-push

@ofog
Copy link
Author

ofog commented Feb 3, 2017

@macdonst I've just removed the plugin, installed with the command above and run the previous code to set the badge. Same outcome, success callback fired but no badge.

@macdonst
Copy link
Member

macdonst commented Feb 3, 2017

@oliverfogden kk, let's comment on SB

@MBuchalik
Copy link

MBuchalik commented Mar 13, 2017

@macdonst Wouldn't it make sense to switch back to SB 1.1.4 (before #1248)? I am experiencing problems on Samsung devices as well. They probably got fixed a few days ago (without a new version so I believe we cannot use it at the moment). But have a look at the issues in this repo - lately, there were many reports from users with completely different devices. Maybe, switching back to 1.1.4 and then (after some time) to a future release like 1.1.14 or 1.1.15 can prevent these problems? 😃

@Jolete
Copy link

Jolete commented Mar 13, 2017

Hi,

I have a Sony Xperia™ Z3 and the Badge has not showed. I can see the push.setApplicationIconBadgeNumber() function is called but I cannot see any badge. I'm working with phonegap/phonegap-plugin-push plugin.

Could I do something to resolve this problem?

Regards

macdonst added a commit that referenced this issue Mar 13, 2017
@macdonst
Copy link
Member

@MBuchalik can you try installing the latest push plugin from master as I upgraded to SB 1.1.13?

@MBuchalik
Copy link

@macdonst Unfortunately, this doesn't fix the issue. I tried the SB test app (IsBadgeWorking) that is running 1.1.13 and badges don't work here as well. (Maybe, this only happens on Samsung devices running Lollipop?)
As you can see in leolin310148/ShortcutBadger#169, it looks like this commit might fix it: leolin310148/ShortcutBadger@6a1ccbf
But no new version has been created by the plugin author, so I guess we cannot use it at the moment.
I am sure this worked when using phonegap-plugin-push 1.8.4. But I can't use this version anymore... That's why I suggested using an older version of SB. Have a look at the comments posted on the issues page of SB in the last few weeks - to me it seems like mine is not the only device that got lost :D

Do you have an idea what can be done to fix this?

Btw: The success function does get fired when running

push.setApplicationIconBadgeNumber(function() {
    console.log("success");
}, function() {
    console.log("error");
}, 1);

I am using PGB and fetched the latest plugin version like this:

<plugin name="phonegap-plugin-push" source="git" spec="https://github.com/phonegap/phonegap-plugin-push">
	<param name="SENDER_ID" value="my sender ID" />
</plugin>

@macdonst
Copy link
Member

@MBuchalik can you just drop the version of SB to 1.1.4 locally and see if it resolves the issue?

@MBuchalik
Copy link

@macdonst Sure! Using version 1.1.4 makes the badge work again on my Samsung Galaxy Alpha with Android 5.0.2.
My tests:

Version Does it work?
1.1.4
1.1.11
1.1.13

macdonst added a commit that referenced this issue Mar 13, 2017
…but firing success function

Trying ShortCut badger v1.1.13
macdonst added a commit that referenced this issue Mar 13, 2017
…but firing success function

Reverting to ShortcutBadger v1.1.11
@macdonst
Copy link
Member

@MBuchalik Okay, I reverted to 1.1.11. Can you give it a try in master?

@MBuchalik
Copy link

@macdonst It seems to be working (at least on my device). I tried the actual push notification (badge in the payload over GCM) and the JavaScript setApplicationIconBadgeNumber() and both are working now 😃 Unfortunately, I only have one Android L device so I can't test it in other environments...

@macdonst
Copy link
Member

@MBuchalik I'm going to leave it as is in master and hope for a new SB release soon. Sadly, I have no devices which can be used to test SB.

@MBuchalik
Copy link

@macdonst Thank you for this change - I hope that a new version of SB will be released soon. At the moment, 1.1.11 should fix the problems I had with Samsung. 😃

Are you planning to release this as a new version of phonegap-plugin-push so that it is possible to grab the changes from npm? (It's no problem if not - I just better like referencing actual version numbers instead of git commits :D)

@Jolete
Copy link

Jolete commented Mar 23, 2017

I would like to comment I have tested with IsBadgeWorking? app and I can see the badge.

@Jolete
Copy link

Jolete commented Mar 23, 2017

My application show the badge in other Android and iOS devices but not in Sony Z3.

@MBuchalik
Copy link

MBuchalik commented Mar 23, 2017

@Jolete Can you try to build it with 4af3472? This uses the same version as the current build of IsBadgeWorking.
Could you also show us the code you are using to set the badge? Does the success callback get called?
(Edit: Did you fetch the latest version from master?)

@Jolete
Copy link

Jolete commented Mar 23, 2017

I have created 30 apps in a automatic way. 15 for Android and 15 for iOS. In a Huawey Honor, Samsung Galaxy tab, iphone 5 and other devices I can see the badget in each apps. But in Sony Xperia Z3 I cannot see the badge with the same apps

image
image

@Jolete
Copy link

Jolete commented Mar 23, 2017

this is the plugin.xml of the push plugin.
plugin.txt

You can change the txt extension to xml.

Could I try any thing more?

@MBuchalik
Copy link

@Jolete am I right that you are using PGB? Currently, you are using version 1.10.0 of the push plugin. Please use the latest version from master (for testing only):

<plugin name="phonegap-plugin-push" source="git" spec="https://github.com/phonegap/phonegap-plugin-push">
    <param name="SENDER_ID" value="your sender ID" />
</plugin>

@macdonst
Copy link
Member

macdonst commented Apr 3, 2017

@Jolete any update?

@Jolete
Copy link

Jolete commented Apr 6, 2017

No. I have to try again... Let me time to test.

@Jolete
Copy link

Jolete commented Apr 6, 2017

PGB?

@Jolete
Copy link

Jolete commented Apr 6, 2017

I have cloned phonegap/phonegap-plugin-push and replace the code of the plugin. Badge is not showed in my Sony Z3. Could I try another thing?

@MBuchalik
Copy link

@Jolete As I said: Can you please try it with 4af3472? This uses shortcut badger 1.1.13 which should be the same as you can see in the IsBadgeWorking app.

What do you mean with "replace the code of the plugin"? What does your config.xml (especially the part where you include the push plugin) now look like? I just want to make sure there is no issue with your configuration...

@Heshyo
Copy link

Heshyo commented Jun 16, 2017

I'm using the push plugin version 1.10.5. On 2 Android 6, not badge is ever visible. On Android 5, the badge is shown but never disappears.
On iOS there's no issue on several iPhones with different iOS.

@MBuchalik
Copy link

@Heshyo What Android 6 devices are you using? Are you sure that badges are supported here?

Could you try https://play.google.com/store/apps/details?id=me.leolin.isbadgeworking ?

@Heshyo
Copy link

Heshyo commented Jun 16, 2017

@MBuchalik Moto G Play on 6.0.1. IsBadgeWorking doesn't work, I don't see any badge on the app.

@MBuchalik
Copy link

@Heshyo I don't see Motorola listed under "Supported launchers" (https://github.com/leolin310148/ShortcutBadger). Doesn't look like Shortcut Badger supports Motorola... Do you have badges on other apps like WhatsApp?

@Heshyo
Copy link

Heshyo commented Jun 19, 2017

@MBuchalik thanks, I thought badges existed on all Android versions.

  • Moto G Play Android 6: vanilla Android, so no badge
  • Wiko Sunny Android 6: no badge, but it might be normal also
  • Samsung S4 Android 5.0.1: badge appears, but never disappears, even after opening the app

@MBuchalik
Copy link

@Heshyo You have to remove the badge when the application starts using setApplicationBadgeNumber with a count set to 0. See https://github.com/phonegap/phonegap-plugin-push/blob/v1.x/docs/API.md#pushsetapplicationiconbadgenumbersuccesshandler-errorhandler-count---ios--android-only

@Heshyo
Copy link

Heshyo commented Jun 27, 2017

@MBuchalik thanks but I have clearBadge: true for both iOS and Android, for me that should be enough, right?

@MBuchalik
Copy link

@Heshyo OK, I have never used clearBadge. According to the docs, the iOS clear badge setting clears the badge when starting the app. The Android one clears the badge before processing notifications and "on init". So I assume you have to call the init function every time the app starts. Do you do this? If no, could you try it? If yes, I cannot really help you at this point. You should probably create a new issue for that and add some details about your configuration.

@Heshyo
Copy link

Heshyo commented Jun 28, 2017

@MBuchalik I do call PushNotification.init on each start of the app, as it's the recommended method. So it may be a different issue as this one.

@MBuchalik
Copy link

@Heshyo Yup, seems so. You should probably create a new issue for that - then it is more likely that it will be seen by someone who has experienced the same problem and/or can help you with that.

@RenateM
Copy link

RenateM commented Jul 19, 2017

@macdonst was a release made for this fix? Having the same issue.

@LightZam
Copy link
Contributor

i have same issue using sony E6653.

it occur error and i think this related to leolin310148/ShortcutBadger#175

@LightZam
Copy link
Contributor

@macdonst
i had checked that using 1.1.17 ShortcutBadger work like a charm.

changing gradle dependencies to compile "me.leolin:ShortcutBadger:1.1.17@aar"

@stale
Copy link

stale bot commented Jun 3, 2018

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 3, 2018
@macdonst macdonst closed this as completed Jun 4, 2018
@lock
Copy link

lock bot commented Jul 4, 2018

This thread has been automatically locked.

@lock lock bot locked as resolved and limited conversation to collaborators Jul 4, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Development

No branches or pull requests

7 participants