diff --git a/README.md b/README.md index c710ea9dc..7fe829edb 100644 --- a/README.md +++ b/README.md @@ -1003,6 +1003,7 @@ window.FirebasePlugin.unregister(); #### setBadgeNumber +iOS only. Set a number on the icon badge: ``` window.FirebasePlugin.setBadgeNumber(3); @@ -1013,7 +1014,10 @@ 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) { @@ -1021,6 +1025,8 @@ window.FirebasePlugin.getBadgeNumber(function(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: ``` diff --git a/src/android/FirebasePlugin.java b/src/android/FirebasePlugin.java index 5c37ebbba..fd2ec2321 100755 --- a/src/android/FirebasePlugin.java +++ b/src/android/FirebasePlugin.java @@ -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.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")) { @@ -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; } @@ -414,36 +412,6 @@ public void run() { }); } - private void setBadgeNumber(final CallbackContext callbackContext, final int number) { - 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() { diff --git a/www/firebase.js b/www/firebase.js index 29f1b3099..b30022237 100644 --- a/www/firebase.js +++ b/www/firebase.js @@ -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]); }; @@ -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", []); };