diff options
| author | Jules Laplace <jules@okfoc.us> | 2015-12-11 02:07:02 -0600 |
|---|---|---|
| committer | Jules Laplace <jules@okfoc.us> | 2015-12-11 02:07:02 -0600 |
| commit | 053473394e6e0990c68a924adbb7c7d75f35973d (patch) | |
| tree | 153e35bebdf4b80e3a2fb23e152754be005e2815 /StoneIsland/plugins/com.parse.cordova.core.pushplugin/src/android/ParsePluginReceiver.java | |
| parent | fb691ed5fbe0122efa1b8eda05c40f2f1272b1b0 (diff) | |
pushplugin on android
Diffstat (limited to 'StoneIsland/plugins/com.parse.cordova.core.pushplugin/src/android/ParsePluginReceiver.java')
| -rw-r--r-- | StoneIsland/plugins/com.parse.cordova.core.pushplugin/src/android/ParsePluginReceiver.java | 61 |
1 files changed, 61 insertions, 0 deletions
diff --git a/StoneIsland/plugins/com.parse.cordova.core.pushplugin/src/android/ParsePluginReceiver.java b/StoneIsland/plugins/com.parse.cordova.core.pushplugin/src/android/ParsePluginReceiver.java new file mode 100644 index 00000000..fa917a48 --- /dev/null +++ b/StoneIsland/plugins/com.parse.cordova.core.pushplugin/src/android/ParsePluginReceiver.java @@ -0,0 +1,61 @@ +package org.apache.cordova.core; + +import com.parse.ParsePushBroadcastReceiver; +import com.parse.ParseAnalytics; + +import android.app.Activity; +import android.app.TaskStackBuilder; +import android.content.Context; +import android.content.Intent; +import android.os.Build; +import android.net.Uri; +import android.util.Log; + +import org.json.JSONObject; +import org.json.JSONException; + +public class ParsePluginReceiver extends ParsePushBroadcastReceiver +{ + private static final String TAG = "ParsePluginReceiver"; + private static final String RECEIVED_IN_FOREGROUND = "receivedInForeground"; + + @Override + protected void onPushReceive(Context context, Intent intent) { + JSONObject pushData = getPushData(intent); + + if (pushData != null) { + if (ParsePlugin.isInForeground()) { + ParsePlugin.javascriptEventCallback(pushData); + } else { + super.onPushReceive(context, intent); + } + } + } + + @Override + protected void onPushOpen(Context context, Intent intent) { + JSONObject pushData = getPushData(intent); + + if (pushData != null) { + if (ParsePlugin.isInForeground()) { + ParseAnalytics.trackAppOpened(intent); + ParsePlugin.javascriptEventCallback(pushData); + } else { + super.onPushOpen(context, intent); + ParsePlugin.setLaunchNotification(pushData); + } + } + } + + private static JSONObject getPushData(Intent intent){ + JSONObject pushData = null; + try { + pushData = new JSONObject(intent.getStringExtra("com.parse.Data")); + pushData.put(RECEIVED_IN_FOREGROUND, ParsePlugin.isInForeground()); + } catch (JSONException e) { + Log.e(TAG, "JSONException while parsing push data:", e); + } finally{ + return pushData; + } + } +} |
