-
Notifications
You must be signed in to change notification settings - Fork 1
/
StarterApp.java
110 lines (94 loc) · 3.88 KB
/
StarterApp.java
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
package com.adpdigital.chabok.starter.application;
import android.util.Log;
import android.os.Bundle;
import org.json.JSONObject;
import android.app.Application;
import com.adpdigital.push.PushMessage;
import com.adpdigital.push.AdpPushClient;
import com.adpdigital.push.ChabokNotification;
import com.adpdigital.push.NotificationHandler;
import android.support.v4.app.NotificationCompat;
import com.adpdigital.chabok.starter.activity.MainActivity;
import static com.adpdigital.chabok.starter.common.Constants.YOUR_APP_ID;
import static com.adpdigital.chabok.starter.common.Constants.SDK_PASSWORD;
import static com.adpdigital.chabok.starter.common.Constants.SDK_USERNAME;
import static com.adpdigital.chabok.starter.common.Constants.YOUR_API_KEY;
public class StarterApp extends Application {
private final String TAG = this.getClass().getName();
private AdpPushClient chabok = null;
@Override
public void onCreate() {
super.onCreate();
initPushClient();
String userId = chabok.getUserId();
if (userId != null && !userId.isEmpty()) {
chabok.register(userId);
} else {
chabok.registerAsGuest();
}
}
private synchronized void initPushClient() {
if (chabok == null) {
chabok = AdpPushClient.init(
getApplicationContext(),
MainActivity.class,
YOUR_APP_ID,
YOUR_API_KEY,
SDK_USERNAME,
SDK_PASSWORD
);
chabok.setDevelopment(true);
chabok.addListener(this);
chabok.addNotificationHandler(getNotificationHandler());
chabok.setDefaultTracker("8iFRmA");
}
}
private NotificationHandler getNotificationHandler(){
return new NotificationHandler(){
@Override
public Class getActivityClass(ChabokNotification chabokNotification) {
// return preferred activity class to be opened on this message's notification
return MainActivity.class;
}
@Override
public boolean buildNotification(ChabokNotification chabokNotification, NotificationCompat.Builder builder) {
// use builder to customize the notification object
// return false to prevent this notification to be shown to the user, otherwise true
getDataFromChabokNotification(chabokNotification);
return true;
}
};
}
private void getDataFromChabokNotification(ChabokNotification chabokNotification) {
if (chabokNotification != null) {
if (chabokNotification.getExtras() != null) {
Bundle payload = chabokNotification.getExtras();
//FCM message data is here
Object data = payload.get("data");
if (data != null) {
Log.d(TAG, "getDataFromChabokNotification: The ChabokNotification data is : " + String.valueOf(data));
}
} else if (chabokNotification.getMessage() != null) {
PushMessage payload = chabokNotification.getMessage();
//Chabok message data is here
JSONObject data = payload.getData();
if (data != null) {
Log.d(TAG, "getDataFromChabokNotification: The ChabokNotification data is : " + data);
}
}
}
}
public void onEvent(PushMessage message) {
Log.d(TAG, "\n\n--------------------\n\nGOT MESSAGE " + message + "\n\n");
JSONObject data = message.getData();
if (data != null){
Log.d(TAG, "--------------------\n\n The message data is : " + data + "\n\n");
}
}
@Override
public void onTerminate() {
if (chabok != null)
chabok.dismiss();
super.onTerminate();
}
}