Skip to content

Commit

Permalink
Remove Android implementation to get/set badge number as it doesn't w…
Browse files Browse the repository at this point in the history
…ork on Android 8+.

Resolves #124.
  • Loading branch information
dpa99c committed Sep 3, 2019
1 parent 92a1740 commit b826d1e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 39 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1003,6 +1003,7 @@ window.FirebasePlugin.unregister();


#### setBadgeNumber
iOS only.
Set a number on the icon badge:
```
window.FirebasePlugin.setBadgeNumber(3);
Expand All @@ -1013,14 +1014,19 @@ Set 0 to clear the badge
window.FirebasePlugin.setBadgeNumber(0);
```

Note: this function is no longer available on Android (see [#124](https://github.com/dpa99c/cordova-plugin-firebasex/issues/124))

#### getBadgeNumber
iOS only.
Get icon badge number:
```
window.FirebasePlugin.getBadgeNumber(function(n) {
console.log(n);
});
```

Note: this function is no longer available on Android (see [#124](https://github.com/dpa99c/cordova-plugin-firebasex/issues/124))

#### clearAllNotifications
Clear all pending notifications from the drawer:
```
Expand Down
44 changes: 6 additions & 38 deletions src/android/FirebasePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,7 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("hasPermission")) {
this.hasPermission(callbackContext);
return true;
} else if (action.equals("setBadgeNumber")) {

This comment has been minimized.

Copy link
@sagrawal31

sagrawal31 Sep 4, 2019

Collaborator

@dpa99c not really sure but do we still need me.leolin:ShortcutBadger:$ANDROID_SHORTCUTBADGER_VERSION?

This comment has been minimized.

Copy link
@dpa99c

dpa99c Sep 4, 2019

Author Owner

No, I forgot to remove it - it can be removed - will do now before I forget

This comment has been minimized.

Copy link
@dpa99c

dpa99c Sep 4, 2019

Author Owner

This comment has been minimized.

Copy link
@sagrawal31

sagrawal31 Sep 4, 2019

Collaborator

Great!

this.setBadgeNumber(callbackContext, args.getInt(0));
return true;
} else if (action.equals("getBadgeNumber")) {
this.getBadgeNumber(callbackContext);
return true;
} else if (action.equals("subscribe")) {
}else if (action.equals("subscribe")) {
this.subscribe(callbackContext, args.getString(0));
return true;
} else if (action.equals("unsubscribe")) {
Expand Down Expand Up @@ -231,7 +225,11 @@ public boolean execute(String action, JSONArray args, CallbackContext callbackCo
} else if (action.equals("setDefaultChannel")) {
this.setDefaultChannel(callbackContext, args.getJSONObject(0));
return true;
} else if (action.equals("grantPermission")) {
} else if (action.equals("grantPermission")
|| action.equals("setBadgeNumber")
|| action.equals("getBadgeNumber")
) {
// Stubs for other platform methods
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.OK, true));
return true;
}
Expand Down Expand Up @@ -414,36 +412,6 @@ public void run() {
});
}

private void setBadgeNumber(final CallbackContext callbackContext, final int number) {

This comment has been minimized.

Copy link
@sagrawal31

sagrawal31 Sep 4, 2019

Collaborator

I was under the impression till today that it was a bug in the plugin since the beginning. But good to know that it doesn't work on A8+

cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
SharedPreferences.Editor editor = cordovaActivity.getSharedPreferences(KEY, Context.MODE_PRIVATE).edit();
editor.putInt(KEY, number);
editor.apply();
ShortcutBadger.applyCount(cordovaActivity, number);
callbackContext.success();
} catch (Exception e) {
handleExceptionWithContext(e, callbackContext);
}
}
});
}

private void getBadgeNumber(final CallbackContext callbackContext) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
try {
SharedPreferences settings = cordovaActivity.getSharedPreferences(KEY, Context.MODE_PRIVATE);
int number = settings.getInt(KEY, 0);
callbackContext.success(number);
} catch (Exception e) {
handleExceptionWithContext(e, callbackContext);
}
}
});
}

private void subscribe(final CallbackContext callbackContext, final String topic) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Expand Down
2 changes: 1 addition & 1 deletion www/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ exports.unregister = function (success, error) {
exec(success, error, "FirebasePlugin", "unregister", []);
};

// Notifications - iOS-only
exports.setBadgeNumber = function (number, success, error) {
exec(success, error, "FirebasePlugin", "setBadgeNumber", [number]);
};
Expand All @@ -45,7 +46,6 @@ exports.getBadgeNumber = function (success, error) {
exec(success, error, "FirebasePlugin", "getBadgeNumber", []);
};

// Notifications - iOS-only
exports.grantPermission = function (success, error) {
exec(success, error, "FirebasePlugin", "grantPermission", []);
};
Expand Down

0 comments on commit b826d1e

Please sign in to comment.