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

Commit

Permalink
Merge branch 'shortcutbadger' of https://github.com/barryvdh/phonegap…
Browse files Browse the repository at this point in the history
…-plugin-push into barryvdh-shortcutbadger
  • Loading branch information
macdonst committed Apr 12, 2016
2 parents bfa5082 + f9f3336 commit 28c78fc
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@

<framework src="com.android.support:support-v13:23+" />
<framework src="com.google.android.gms:play-services-gcm:+" />
<framework src="me.leolin:ShortcutBadger:1.1.4@aar" />

<source-file src="src/android/com/adobe/phonegap/push/GCMIntentService.java" target-dir="src/com/adobe/phonegap/push/" />
<source-file src="src/android/com/adobe/phonegap/push/PushConstants.java" target-dir="src/com/adobe/phonegap/push/" />
Expand Down
6 changes: 6 additions & 0 deletions src/android/com/adobe/phonegap/push/GCMIntentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,16 @@ private void showNotificationIfPossible (Context context, Bundle extras) {
String message = extras.getString(MESSAGE);
String title = extras.getString(TITLE);
String contentAvailable = extras.getString(CONTENT_AVAILABLE);
String badgeCount = extras.getString(COUNT);

Log.d(LOG_TAG, "message =[" + message + "]");
Log.d(LOG_TAG, "title =[" + title + "]");
Log.d(LOG_TAG, "contentAvailable =[" + contentAvailable + "]");
Log.d(LOG_TAG, "badgeCount =[" + badgeCount + "]");

if (badgeCount != null) {
PushPlugin.setApplicationIconBadgeNumber(context, Integer.parseInt(badgeCount));
}

if ((message != null && message.length() != 0) ||
(title != null && title.length() != 0)) {
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 @@ -54,4 +54,5 @@ public interface PushConstants {
public static final String GCM = "GCM";
public static final String CONTENT_AVAILABLE = "content-available";
public static final String TOPICS = "topics";
public static final String SET_APPLICATION_ICON_BADGE_NUMBER = "setApplicationIconBadgeNumber";
}
22 changes: 22 additions & 0 deletions src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
import java.util.HashSet;
import java.util.Iterator;

import me.leolin.shortcutbadger.ShortcutBadger;

public class PushPlugin extends CordovaPlugin implements PushConstants {

public static final String LOG_TAG = "PushPlugin";
Expand Down Expand Up @@ -179,6 +181,18 @@ public void run() {
}
}
});
} else if (SET_APPLICATION_ICON_BADGE_NUMBER.equals(action)) {
cordova.getThreadPool().execute(new Runnable() {
public void run() {
Log.v(LOG_TAG, "setApplicationIconBadgeNumber: data=" + data.toString());
try {
setApplicationIconBadgeNumber(getApplicationContext(), data.getJSONObject(0).getInt(BADGE));
} catch (JSONException e) {
callbackContext.error(e.getMessage());
}
callbackContext.success();
}
});
} else {
Log.e(LOG_TAG, "Invalid action : " + action);
callbackContext.sendPluginResult(new PluginResult(PluginResult.Status.INVALID_ACTION));
Expand Down Expand Up @@ -219,6 +233,14 @@ public static void sendExtras(Bundle extras) {
}
}

public static void setApplicationIconBadgeNumber(Context context, int badgeCount) {
if (badgeCount > 0) {
ShortcutBadger.applyCount(context, badgeCount);
} else {
ShortcutBadger.removeCount(context);
}
}

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
super.initialize(cordova, webView);
Expand Down

0 comments on commit 28c78fc

Please sign in to comment.