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

Commit

Permalink
Cache multiple Android action button pushes if app is not running (#1272
Browse files Browse the repository at this point in the history
)

* Use unique pending intent request code to enable multiple simultaneous notifications with action buttons

* Append i to notId to ensure pending intent request code is unique when multiple notId's are sequential

* Use random number for Android action button pending intent request codes

* By nicoabie: Cache multiple Android action button presses if the app is in the background (resolved conflicts)

* import java.util.ArrayList

* Revert changes to index.spec.js

* Use a synchonized list for gCachedExtras
  • Loading branch information
mikepsinn authored and macdonst committed Oct 17, 2016
1 parent 3bf9ff5 commit d0547ba
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/android/com/adobe/phonegap/push/PushPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.List;

import me.leolin.shortcutbadger.ShortcutBadger;

Expand All @@ -31,7 +33,7 @@ public class PushPlugin extends CordovaPlugin implements PushConstants {

private static CallbackContext pushContext;
private static CordovaWebView gWebView;
private static Bundle gCachedExtras = null;
private static List<Bundle> gCachedExtras = Collections.synchronizedList(new ArrayList<Bundle>());
private static boolean gForeground = false;

/**
Expand Down Expand Up @@ -133,10 +135,15 @@ else if (!savedSenderID.equals(senderID)) {

}

if (gCachedExtras != null) {
if (!gCachedExtras.isEmpty()) {
Log.v(LOG_TAG, "sending cached extras");
sendExtras(gCachedExtras);
gCachedExtras = null;
synchronized(gCachedExtras) {
Iterator<Bundle> gCachedExtrasIterator = gCachedExtras.iterator();
while (gCachedExtrasIterator.hasNext()) {
sendExtras(gCachedExtrasIterator.next());
}
}
gCachedExtras.clear();
}
}
});
Expand Down Expand Up @@ -169,8 +176,8 @@ public void run() {
} catch (IOException e) {
Log.e(LOG_TAG, "execute: Got JSON Exception " + e.getMessage());
callbackContext.error(e.getMessage());
}
}
}
});
} else if (FINISH.equals(action)) {
callbackContext.success();
Expand Down Expand Up @@ -279,7 +286,7 @@ public static void sendExtras(Bundle extras) {
sendEvent(convertBundleToJson(extras));
} else {
Log.v(LOG_TAG, "sendExtras: caching extras to send at a later time.");
gCachedExtras = extras;
gCachedExtras.add(extras);
}
}
}
Expand Down

0 comments on commit d0547ba

Please # to comment.