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

Set get badge count android #1644

Merged
merged 7 commits into from
Apr 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/API.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
- [push.subscribe()](#pushsubscribetopic-successhandler-errorhandler)
- [push.unsubscribe()](#pushunsubscribetopic-successhandler-errorhandler)
- [push.setApplicationIconBadgeNumber() - iOS & Android only](#pushsetapplicationiconbadgenumbersuccesshandler-errorhandler-count---ios--android-only)
- [push.getApplicationIconBadgeNumber() - iOS only](#pushgetapplicationiconbadgenumbersuccesshandler-errorhandler---ios-only)
- [push.getApplicationIconBadgeNumber() - iOS & Android only](#pushgetapplicationiconbadgenumbersuccesshandler-errorhandler---ios--android-only)
- [push.finish() - iOS only](#pushfinishsuccesshandler-errorhandler-id---ios-only)
- [push.clearAllNotifications() - iOS & Android only](#pushclearallnotificationssuccesshandler-errorhandler---ios--android-only)

Expand Down Expand Up @@ -355,7 +355,7 @@ push.setApplicationIconBadgeNumber(function() {
}, 2);
```

## push.getApplicationIconBadgeNumber(successHandler, errorHandler) - iOS only
## push.getApplicationIconBadgeNumber(successHandler, errorHandler) - iOS & Android only

Get the current badge count visible when the app is not running

Expand Down
1 change: 1 addition & 0 deletions src/android/com/adobe/phonegap/push/PushConstants.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public interface PushConstants {
public static final String CONTENT_AVAILABLE = "content-available";
public static final String TOPICS = "topics";
public static final String SET_APPLICATION_ICON_BADGE_NUMBER = "setApplicationIconBadgeNumber";
public static final String GET_APPLICATION_ICON_BADGE_NUMBER = "getApplicationIconBadgeNumber";
public static final String CLEAR_ALL_NOTIFICATIONS = "clearAllNotifications";
public static final String VISIBILITY = "visibility";
public static final String INLINE_REPLY = "inlineReply";
Expand Down
24 changes: 23 additions & 1 deletion src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,13 @@ public void run() {
callbackContext.success();
}
});
} else if (GET_APPLICATION_ICON_BADGE_NUMBER.equals(action)) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Log.v(LOG_TAG, "getApplicationIconBadgeNumber");
callbackContext.success(getApplicationIconBadgeNumber(getApplicationContext()));
}
});
} else if (CLEAR_ALL_NOTIFICATIONS.equals(action)) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Expand Down Expand Up @@ -274,12 +281,27 @@ public static void sendExtras(Bundle extras) {
}
}

/*
* Retrives badge count from SharedPreferences
*/
public static int getApplicationIconBadgeNumber(Context context){
SharedPreferences settings = context.getSharedPreferences(BADGE, Context.MODE_PRIVATE);
return settings.getInt(BADGE, 0);
}

/*
* Sets badge count on application icon and in SharedPreferences
*/
public static void setApplicationIconBadgeNumber(Context context, int badgeCount) {
if (badgeCount > 0) {
ShortcutBadger.applyCount(context, badgeCount);
} else {
}else{
ShortcutBadger.removeCount(context);
}

SharedPreferences.Editor editor = context.getSharedPreferences(BADGE, Context.MODE_PRIVATE).edit();
editor.putInt(BADGE, Math.max(badgeCount, 0));
editor.apply();
}

@Override
Expand Down