forked from SIROK-archive/growthpush-unity
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnityActivity.java
More file actions
143 lines (120 loc) · 3.55 KB
/
UnityActivity.java
File metadata and controls
143 lines (120 loc) · 3.55 KB
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
package com.growthpush;
//import org.json.JSONException;
//import org.json.JSONObject;
import android.os.Bundle;
import android.util.Log;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.Intent;
import com.growthpush.handler.DefaultReceiveHandler;
import com.unity3d.player.UnityPlayer;
import com.unity3d.player.UnityPlayerActivity;
@SuppressLint("NewApi")
public class UnityActivity extends UnityPlayerActivity {
private static String growthPushMessage = null;
public static void saveGrowthPushMessage(String msg)
{
growthPushMessage = msg;
}
public static void callTrackGrowthPushMessage()
{
if(growthPushMessage != null)
{
UnityPlayer.UnitySendMessage("GrowthPushReceiveAndroid", "launchWithNotification", growthPushMessage);
growthPushMessage = null;
}
}
public static String parsePushGrowthPushMessage(Intent intent)
{
String str = null;
Bundle bundle = null;
if(intent != null)
bundle = intent.getExtras();
if(bundle != null)
{
str = "";
for (String key : bundle.keySet()) {
String value = bundle.get(key).toString();
Log.d("unity", key + " => " + value);
if(key.equals("showDialog") || key.equals("collapse_key") || key.equals("from"))
continue;
str += String.format("&%s=%s", key, value);
}
/*
String str = "{";
String notification = bundle.getString("notification", null);
Log.d("unity", String.format("Native notification: %s", notification));
if(notification != null)
str += String.format("\"notification\":\"%s\"", notification);
String growthpush = bundle.getString("growthpush", null);
Log.d("unity", String.format("Native growthpush %s", growthpush));
if(growthpush != null)
{
if(notification != null)
str += ",";
str += String.format("\"growthpush\":%s", growthpush);
}
str += "}";
UnityPlayer.UnitySendMessage("GrowthPushReceiveAndroid", "launchWithNotification", str);
*/
/*
if (additionalFieldJson != null) {
try {
JSONObject additionalField = new JSONObject(additionalFieldJson);
if (additionalField.has("notificationId")) {
notificationId = additionalField.getInt("notificationId");
}
} catch (JSONException e) {
}
}*/
}
return str;
}
private boolean started = false;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.d("unity", "onCreate");
DefaultReceiveHandler receiveHandler = new DefaultReceiveHandler() {
@Override
public void onReceive(Context context, Intent intent) {
Log.d("unity", "onReceive");
super.onReceive(context, intent);
}
};
receiveHandler.setCallback(new DefaultReceiveHandler.Callback() {
@Override
public void onOpen(Context context, Intent intent) {
Log.d("unity", "onOpen");
super.onOpen(context, intent);
String str = UnityActivity.parsePushGrowthPushMessage(intent);
if(str != null)
{
UnityPlayer.UnitySendMessage("GrowthPushReceiveAndroid", "launchWithNotification", str);
}
else
{
GrowthPush.getInstance().trackEvent("Launch");
}
}
});
GrowthPush.getInstance().setReceiveHandler(receiveHandler);
}
@Override
protected void onStart ()
{
Log.d("unity", "onStart");
super.onStart();
GrowthPush.getInstance().trackEvent("Launch");
started = true;
}
@Override
protected void onResume()
{
Log.d("unity", "onResume");
super.onResume();
if(!started)
GrowthPush.getInstance().trackEvent("Launch");
started = false;
}
}