blob: fa917a48c280dafb0124792f773cce5f8b7be9e6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
}
}
}
|