cordova-plugin-appice 2.0.10 → 2.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/example/www/js/index.js +90 -81
- package/package.json +1 -1
- package/plugin.xml +7 -4
- package/scripts/BeforeAndroidBuilt.js +63 -34
- package/src/android/AppICEFCMPush.java +26 -0
- package/src/android/AppICEMFPPush.java +24 -134
- package/src/android/AppICEPlugin.java +118 -11
- package/src/android/AppICEPushHandler.java +163 -0
- package/src/ios/AppDelegate+AppICEPlugin.m +177 -87
- package/src/ios/AppICEPlugin.h +3 -0
- package/src/ios/AppICEPlugin.m +21 -86
- package/www/AppICE.js +310 -263
package/example/www/js/index.js
CHANGED
|
@@ -1,102 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
* Licensed to the Apache Software Foundation (ASF) under one
|
|
3
|
-
* or more contributor license agreements. See the NOTICE file
|
|
4
|
-
* distributed with this work for additional information
|
|
5
|
-
* regarding copyright ownership. The ASF licenses this file
|
|
6
|
-
* to you under the Apache License, Version 2.0 (the
|
|
7
|
-
* "License"); you may not use this file except in compliance
|
|
8
|
-
* with the License. You may obtain a copy of the License at
|
|
9
|
-
*
|
|
10
|
-
* http://www.apache.org/licenses/LICENSE-2.0
|
|
11
|
-
*
|
|
12
|
-
* Unless required by applicable law or agreed to in writing,
|
|
13
|
-
* software distributed under the License is distributed on an
|
|
14
|
-
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
15
|
-
* KIND, either express or implied. See the License for the
|
|
16
|
-
* specific language governing permissions and limitations
|
|
17
|
-
* under the License.
|
|
18
|
-
*/
|
|
19
|
-
|
|
20
|
-
// Wait for the deviceready event before using any of Cordova's device APIs.
|
|
21
|
-
// See https://cordova.apache.org/docs/en/latest/cordova/events/events.html#deviceready
|
|
1
|
+
|
|
22
2
|
document.addEventListener('deviceready', onDeviceReady, false);
|
|
23
3
|
|
|
4
|
+
function testing(deeplink, type) {
|
|
5
|
+
var t1 = JSON.stringify(deeplink);
|
|
6
|
+
console.log("testing " + type + " " + t1)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
AppICE.getDataForKey(deeplink, "cdata", function(result) {
|
|
11
|
+
navigator.notification.alert(
|
|
12
|
+
result, // message
|
|
13
|
+
alertDismissed, // callback
|
|
14
|
+
'For Key = cdata', // title
|
|
15
|
+
'Done' // buttonName
|
|
16
|
+
);
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function alertDismissed() {
|
|
21
|
+
// do something
|
|
22
|
+
}
|
|
23
|
+
|
|
24
24
|
function onDeviceReady() {
|
|
25
|
-
|
|
25
|
+
// Cordova is now initialized. Have fun!
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
27
|
+
console.log('Running cordova-' + cordova.platformId + '@' + cordova.version);
|
|
28
|
+
document.getElementById('deviceready').classList.add('ready');
|
|
29
|
+
document.addEventListener('pushNotificationClicked', e => { testing(e.notification, "notificationCallback") })
|
|
30
|
+
document.addEventListener('pushNotificationClicked', pushNotificationClicked);
|
|
31
|
+
initializesdk()
|
|
30
32
|
}
|
|
33
|
+
function pushNotificationClicked(payload, type) {
|
|
34
|
+
console.log('in testing method');
|
|
35
|
+
//var t1 = JSON.stringify(payload);
|
|
36
|
+
var newPayload = payload['payload'];
|
|
37
|
+
console.log("testing " + type);
|
|
31
38
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
// certs = ["assets/ai_android.pem"]; this is for enabling ssl pinning if no ssl certificates pass null
|
|
37
|
-
console.log("certs : ", certs);
|
|
38
|
-
AppICE.initSdk("5bebe93c25d705690ffbc758", "9e9ec60197c8373a11ac15ce4dae80e973608ab2", "d985715d1bb48942d36d5d08de3b6a8c", "",
|
|
39
|
-
"US",
|
|
40
|
-
"https://a.appice.io",
|
|
41
|
-
certs,
|
|
42
|
-
function (success) {
|
|
43
|
-
console.log("init success", success);
|
|
44
|
-
}, function (error) {
|
|
45
|
-
console.log("init Failed", error);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
AppICE.setSessionTimeout(1800,
|
|
50
|
-
function(success){
|
|
51
|
-
console.log("Session success " + success);
|
|
52
|
-
},function(error){
|
|
53
|
-
console.log("Session Failed "+ error);
|
|
54
|
-
}
|
|
55
|
-
);
|
|
39
|
+
AppICE.getDataForKey(newPayload, 'eurl', function(result) {
|
|
40
|
+
console.log('result getDataForKey method' + result);
|
|
41
|
+
|
|
42
|
+
});
|
|
56
43
|
}
|
|
44
|
+
// initialize appice sdk
|
|
45
|
+
document.getElementById("initsdk").addEventListener("click", initializesdk);
|
|
46
|
+
function initializesdk() {
|
|
47
|
+
var certs = [];
|
|
48
|
+
// certs = ["assets/ai_android.pem"]; this is for enabling ssl pinning if no ssl certificates pass null
|
|
49
|
+
console.log("certs : ", certs);
|
|
50
|
+
AppICE.initSdk("5bebe93c25d705690ffbc758", "9e9ec60197c8373a11ac15ce4dae80e973608ab2", "d985715d1bb48942d36d5d08de3b6a8c", "",
|
|
51
|
+
"US",
|
|
52
|
+
"https://a.appice.io",
|
|
53
|
+
certs,
|
|
54
|
+
function (success) {
|
|
55
|
+
console.log("init success", success);
|
|
57
56
|
|
|
58
57
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
58
|
+
}, function (error) {
|
|
59
|
+
console.log("init Failed", error);
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
AppICE.setSessionTimeout(1800,
|
|
63
|
+
function (success) {
|
|
64
|
+
console.log("Session success " + success);
|
|
65
|
+
}, function (error) {
|
|
66
|
+
console.log("Session Failed " + error);
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
69
|
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
//set user id
|
|
73
|
+
document.getElementById("userid").addEventListener("click", userid);
|
|
74
|
+
function userid() {
|
|
75
|
+
const userid = ["987"];
|
|
76
|
+
|
|
77
|
+
AppICE.registerLifeCycle(function (success) {
|
|
78
|
+
console.log("registerLifeCycle success", success);
|
|
79
|
+
}, function (error) {
|
|
80
|
+
console.log("registerLifeCycle Failed", error);
|
|
81
|
+
});
|
|
72
82
|
|
|
83
|
+
}
|
|
73
84
|
|
|
74
85
|
//set user details
|
|
75
86
|
document.getElementById("userinfo").addEventListener("click", userinfo);
|
|
76
|
-
function userinfo(){
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
87
|
+
function userinfo() {
|
|
88
|
+
AppICE.setUser("Jhon Doe", "9876543210", "a@gmail.com", function (success) {
|
|
89
|
+
console.log("Set user success", success);
|
|
90
|
+
}, function (error) {
|
|
91
|
+
console.log("Set user error", error);
|
|
92
|
+
});
|
|
82
93
|
}
|
|
83
94
|
|
|
84
|
-
|
|
85
95
|
//get event
|
|
86
96
|
document.getElementById("event").addEventListener("click", allevent);
|
|
87
|
-
function allevent(){
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
}, function(error) {
|
|
99
|
-
console.error("tagEvent Error : " + error);
|
|
100
|
-
});
|
|
101
|
-
}
|
|
97
|
+
function allevent() {
|
|
98
|
+
console.log("inside event method");
|
|
99
|
+
var dataObj = {
|
|
100
|
+
"ClickedMenuBtn": "false",
|
|
101
|
+
"CLickedSubmitBtn": "false",
|
|
102
|
+
"AppName": "SampleApp"
|
|
103
|
+
};
|
|
104
|
+
AppICE.tagEvent("SampleApp", dataObj,
|
|
105
|
+
function (success) {
|
|
106
|
+
console.log("tagEvent success: " + JSON.stringify(success));
|
|
102
107
|
|
|
108
|
+
}, function (error) {
|
|
109
|
+
console.error("tagEvent Error : " + error);
|
|
110
|
+
});
|
|
111
|
+
}
|
package/package.json
CHANGED
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
|
2
|
-
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-appice" version="2.
|
|
2
|
+
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0" id="cordova-plugin-appice" version="2.1.2">
|
|
3
3
|
<name>AppICE</name>
|
|
4
4
|
<description>AppICE Plugin for Cordova/PhoneGap</description>
|
|
5
5
|
<license>Commercial</license>
|
|
@@ -39,7 +39,7 @@
|
|
|
39
39
|
|
|
40
40
|
<podspec>
|
|
41
41
|
<pods>
|
|
42
|
-
<pod name="AppICE-IOS-SDK" spec="1.7.
|
|
42
|
+
<pod name="AppICE-IOS-SDK" spec="1.7.69" />
|
|
43
43
|
</pods>
|
|
44
44
|
</podspec>
|
|
45
45
|
|
|
@@ -113,12 +113,15 @@
|
|
|
113
113
|
<preference name="WORK_MANAGER_VERSION" default="2.7.1"/>
|
|
114
114
|
|
|
115
115
|
<!-- AppICE VERSION-->
|
|
116
|
-
<preference name="APPICE_VERSION" default="2.5.
|
|
116
|
+
<preference name="APPICE_VERSION" default="2.5.69"/>
|
|
117
117
|
|
|
118
118
|
|
|
119
119
|
<!-- USES PERMISSION -->
|
|
120
120
|
<config-file target="AndroidManifest.xml" parent="/manifest">
|
|
121
121
|
<uses-permission android:name="android.permission.INTERNET"/>
|
|
122
|
+
|
|
123
|
+
<uses-permission android:name="android.permission.SCHEDULE_EXACT_ALARM" />
|
|
124
|
+
<uses-permission android:name="android.permission.USE_EXACT_ALARM" />
|
|
122
125
|
</config-file>
|
|
123
126
|
|
|
124
127
|
<!-- MANIFEST ENTRIES -->
|
|
@@ -170,7 +173,7 @@
|
|
|
170
173
|
</config-file>
|
|
171
174
|
|
|
172
175
|
<!-- CLASSES PATH -->
|
|
173
|
-
|
|
176
|
+
<source-file src="src/android/AppICEPushHandler.java" target-dir="com/appice/cordova/" />
|
|
174
177
|
<source-file src="src/android/AppICEPlugin.java" target-dir="com/appice/cordova/" />
|
|
175
178
|
<source-file src="src/android/CampaignCampsReceiver.java" target-dir="com/appice/cordova/" />
|
|
176
179
|
<source-file src="src/android/NotificationEventService.java" target-dir="com/appice/cordova/" />
|
|
@@ -22,9 +22,10 @@ module.exports = function (context) {
|
|
|
22
22
|
///for SSL pinning
|
|
23
23
|
|
|
24
24
|
var appBuildGradlePath = path.join(platformRoot, 'app/build.gradle'); // Path to the app's build.gradle file
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
const pluginName = 'cordova-plugin-appice';
|
|
26
|
+
const pluginXmlPath = path.join(context.opts.projectRoot, 'plugins', pluginName, 'plugin.xml');
|
|
27
|
+
const sourceFileEntry = '<source-file src="src/android/AppICEMFPPush.java" target-dir="com/appice/cordova/" />';
|
|
28
|
+
const sourceFileEntryFCM = '<source-file src="src/android/AppICEFCMPush.java" target-dir="com/appice/cordova/" />';
|
|
28
29
|
|
|
29
30
|
if (MFP_PUSH === "true") {
|
|
30
31
|
var manifestFileNew = path.join(platformRoot, '/app/src/main/AndroidManifest.xml');
|
|
@@ -44,7 +45,6 @@ module.exports = function (context) {
|
|
|
44
45
|
throw new Error('Unable to write into AndroidManifest.xml: ' + err);
|
|
45
46
|
}
|
|
46
47
|
});
|
|
47
|
-
|
|
48
48
|
}
|
|
49
49
|
});
|
|
50
50
|
} catch (err) {
|
|
@@ -74,20 +74,20 @@ module.exports = function (context) {
|
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
try {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
77
|
+
const pluginXmlContent = fs.readFileSync(pluginXmlPath, 'utf8');
|
|
78
|
+
|
|
79
|
+
if (pluginXmlContent.indexOf(sourceFileEntry) === -1) {
|
|
80
|
+
const platformPosition = pluginXmlContent.indexOf('<platform name="android">');
|
|
81
|
+
const updatedPluginXmlContent = pluginXmlContent.slice(0, platformPosition) + '\n' + sourceFileEntry + '\n' + pluginXmlContent.slice(platformPosition);
|
|
82
|
+
|
|
83
|
+
fs.writeFileSync(pluginXmlPath, updatedPluginXmlContent, 'utf8');
|
|
84
|
+
console.log(`Added <source-file> entry to ${pluginXmlPath}`);
|
|
85
|
+
} else {
|
|
86
|
+
console.log(`<source-file> entry already exists in ${pluginXmlPath}`);
|
|
87
|
+
}
|
|
88
|
+
} catch (err) {
|
|
89
|
+
console.error(`Failed to modify ${pluginXmlPath}: ${err}`);
|
|
90
|
+
}
|
|
91
91
|
} else {
|
|
92
92
|
var manifestFileNewRoot = path.join(platformRoot, 'AndroidManifest.xml');
|
|
93
93
|
if (fs.existsSync(manifestFileNewRoot)) {
|
|
@@ -105,32 +105,61 @@ module.exports = function (context) {
|
|
|
105
105
|
throw new Error('Unable to write into AndroidManifest.xml: ' + err);
|
|
106
106
|
}
|
|
107
107
|
});
|
|
108
|
-
|
|
109
108
|
}
|
|
110
109
|
});
|
|
111
110
|
} catch (err) {
|
|
112
111
|
}
|
|
113
112
|
}
|
|
114
113
|
}
|
|
114
|
+
} else {
|
|
115
115
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
116
|
+
const manifestPath = '/app/src/main/AndroidManifest.xml';
|
|
117
|
+
|
|
118
|
+
// Read existing manifest file
|
|
119
|
+
fs.readFile(manifestPath, 'utf-8', (err, data) => {
|
|
120
|
+
if (err) {
|
|
121
|
+
console.error('Error reading manifest file:', err);
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
// Find the position to insert the service tag
|
|
126
|
+
const serviceIntentFilter = ' <intent-filter>\n <action android:name="com.google.firebase.MESSAGING_EVENT" />\n </intent-filter>\n';
|
|
127
|
+
const serviceTag = ` <service android:name="com.appice.cordova.AppICEFCMPush">\n${serviceIntentFilter} </service>\n`;
|
|
128
|
+
|
|
129
|
+
const index = data.indexOf('</application>');
|
|
130
|
+
if (index === -1) {
|
|
131
|
+
console.error('Error: Could not find </application> tag in AndroidManifest.xml');
|
|
132
|
+
return;
|
|
129
133
|
}
|
|
130
|
-
|
|
131
|
-
|
|
134
|
+
|
|
135
|
+
// Insert the service tag just before the </application> tag
|
|
136
|
+
const updatedManifest = data.slice(0, index) + serviceTag + data.slice(index);
|
|
137
|
+
|
|
138
|
+
// Write the updated manifest back to file
|
|
139
|
+
fs.writeFile(manifestPath, updatedManifest, 'utf-8', (err) => {
|
|
140
|
+
if (err) {
|
|
141
|
+
console.error('Error writing manifest file:', err);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
console.log('Firebase Cloud Messaging service tag added to AndroidManifest.xml successfully!');
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
try {
|
|
148
|
+
const pluginXmlContent = fs.readFileSync(pluginXmlPath, 'utf8');
|
|
149
|
+
|
|
150
|
+
if (pluginXmlContent.indexOf(sourceFileEntry) === -1) {
|
|
151
|
+
const platformPosition = pluginXmlContent.indexOf('<platform name="android">');
|
|
152
|
+
const updatedPluginXmlContent = pluginXmlContent.slice(0, platformPosition) + '\n' + sourceFileEntryFCM + '\n' + pluginXmlContent.slice(platformPosition);
|
|
153
|
+
|
|
154
|
+
fs.writeFileSync(pluginXmlPath, updatedPluginXmlContent, 'utf8');
|
|
155
|
+
console.log(`Added <source-file> entry to ${pluginXmlPath}`);
|
|
156
|
+
} else {
|
|
157
|
+
console.log(`<source-file> entry already exists in ${pluginXmlPath}`);
|
|
132
158
|
}
|
|
159
|
+
} catch (err) {
|
|
160
|
+
console.error(`Failed to modify ${pluginXmlPath}: ${err}`);
|
|
133
161
|
}
|
|
162
|
+
|
|
134
163
|
}
|
|
135
164
|
|
|
136
165
|
if (SSL_PINNING === "true") {
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
package com.appice.cordova;
|
|
2
|
+
|
|
3
|
+
import androidx.annotation.NonNull;
|
|
4
|
+
|
|
5
|
+
import com.google.firebase.messaging.FirebaseMessagingService;
|
|
6
|
+
import com.google.firebase.messaging.RemoteMessage;
|
|
7
|
+
|
|
8
|
+
public class AppICEFCMPush extends FirebaseMessagingService {
|
|
9
|
+
private final AppICEPushHandler appICEPushHandler = new AppICEPushHandler();
|
|
10
|
+
|
|
11
|
+
@Override
|
|
12
|
+
public void onNewToken(@NonNull String token) {
|
|
13
|
+
super.onNewToken(token);
|
|
14
|
+
appICEPushHandler.onNewToken(token, getApplicationContext());
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
@Override
|
|
18
|
+
public void onMessageReceived(@NonNull RemoteMessage message) {
|
|
19
|
+
super.onMessageReceived(message);
|
|
20
|
+
if(appICEPushHandler.isAppICEPush(message)) {
|
|
21
|
+
appICEPushHandler.onMessageReceived(message, getApplicationContext());
|
|
22
|
+
}else{
|
|
23
|
+
// handle your customise push payload here
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -1,55 +1,40 @@
|
|
|
1
1
|
package com.appice.cordova;
|
|
2
2
|
|
|
3
|
-
import android.app.PendingIntent;
|
|
4
|
-
import android.content.Context;
|
|
5
|
-
import android.content.Intent;
|
|
6
|
-
import android.os.Build;
|
|
7
3
|
import android.util.Log;
|
|
8
4
|
|
|
9
5
|
import androidx.annotation.NonNull;
|
|
6
|
+
|
|
10
7
|
import com.google.firebase.messaging.RemoteMessage;
|
|
11
8
|
import com.ibm.mobilefirstplatform.clientsdk.android.push.api.MFPPushIntentService;
|
|
12
9
|
import com.ibm.mobilefirstplatform.clientsdk.android.push.internal.MFPInternalPushMessage;
|
|
10
|
+
|
|
13
11
|
import org.json.JSONObject;
|
|
14
12
|
|
|
15
13
|
import java.util.Map;
|
|
16
14
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
/* import path for MainActivity */
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
/*=============================*/
|
|
24
|
-
|
|
25
|
-
public class AppICEMFPPush extends MFPPushIntentService {
|
|
26
|
-
private static final String TAG = AppICEMFPPush.class.getSimpleName();
|
|
27
|
-
private static final String ACTION = "com.appice.campaignEvent";
|
|
28
|
-
private static final String PUSH_PAYLOAD = "ai_content";
|
|
29
|
-
private static final String MESSAGE = "message";
|
|
30
|
-
private static final String EXTERNAL_TYPE = "et";
|
|
31
|
-
private static final String DEEPLINK = "dl";
|
|
32
|
-
private static final String LANDING_PAGE = "lp";
|
|
15
|
+
public class AppICEMFPPush extends MFPPushIntentService{
|
|
16
|
+
private static final String TAG = AppICEMFPPush.class.getName();
|
|
17
|
+
private final AppICEPushHandler appICEPushHandler = new AppICEPushHandler();
|
|
33
18
|
|
|
34
19
|
@Override
|
|
35
20
|
public void onMessageReceived(RemoteMessage message) {
|
|
36
|
-
if (message != null)
|
|
37
|
-
onMessageReceived(message, null, null, getApplicationContext());
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
public void onMessageReceived(RemoteMessage message, PendingIntent createPendingIntent, PendingIntent deletePendingIntent, Context context) {
|
|
41
|
-
Map<String, String> data = message.getData();
|
|
42
21
|
MFPPushIntentService mfpPushIntentService = new MFPPushIntentService();
|
|
43
|
-
boolean isAppICEPayload = ContextSdk.isAppICENotification(message);
|
|
44
22
|
int collapseId = -1;
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
23
|
+
if (appICEPushHandler.isAppICEPush(message)){
|
|
24
|
+
appICEPushHandler.onMessageReceived(message, getApplicationContext());
|
|
25
|
+
}else {
|
|
26
|
+
|
|
27
|
+
/*
|
|
28
|
+
* if you have your customise code for MFP push then
|
|
29
|
+
* you can pass this remote message to your custom class
|
|
30
|
+
* rather calling mfpIntent directly
|
|
31
|
+
*
|
|
32
|
+
* you can also extend your custom class
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
// in case if there will no custom class
|
|
36
|
+
Map<String, String> data = message.getData();
|
|
37
|
+
JSONObject payload = null;
|
|
53
38
|
try {
|
|
54
39
|
JSONObject dataPayload = new JSONObject(data);
|
|
55
40
|
if (dataPayload != null) {
|
|
@@ -62,7 +47,6 @@ public class AppICEMFPPush extends MFPPushIntentService {
|
|
|
62
47
|
} catch (Exception e) {
|
|
63
48
|
Log.e(TAG, "onMessageReceived: error ", e);
|
|
64
49
|
}
|
|
65
|
-
|
|
66
50
|
try {
|
|
67
51
|
if (collapseId != -1) {
|
|
68
52
|
mfpPushIntentService.onNotificationReceived(data, collapseId);
|
|
@@ -76,102 +60,8 @@ public class AppICEMFPPush extends MFPPushIntentService {
|
|
|
76
60
|
}
|
|
77
61
|
|
|
78
62
|
@Override
|
|
79
|
-
public void onNewToken(@NonNull String
|
|
80
|
-
super.onNewToken(
|
|
81
|
-
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
/*======================================
|
|
86
|
-
* define your launch activity here
|
|
87
|
-
* also do the import for that activity for ex : import com.appice.sample.MainActivity;
|
|
88
|
-
* uncomment this try block
|
|
89
|
-
========================================*/
|
|
90
|
-
|
|
91
|
-
public static PendingIntent createPendingIntent(String message, Context mContext) {
|
|
92
|
-
PendingIntent pendingIntent = null;
|
|
93
|
-
// uncomment this if you are using MFP service
|
|
94
|
-
// pendingIntent= internalCreatePendingIntent(message, mContext);
|
|
95
|
-
return pendingIntent;
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
public static PendingIntent deletePendingIntent(Context mContext) {
|
|
99
|
-
PendingIntent pendingIntent = null;
|
|
100
|
-
|
|
101
|
-
// uncomment this if you are using MFP service
|
|
102
|
-
//pendingIntent = internalDeletePendingIntent(mContext);
|
|
103
|
-
return pendingIntent;
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
//================================
|
|
107
|
-
// internal helper fucntion
|
|
108
|
-
//================================
|
|
109
|
-
private static PendingIntent internalCreatePendingIntent(String message, Context mContext){
|
|
110
|
-
try {
|
|
111
|
-
// please use your launch activity here
|
|
112
|
-
Intent clickIntent = new Intent(mContext, MainActivity.class);
|
|
113
|
-
|
|
114
|
-
final Intent newIntent = new Intent();
|
|
115
|
-
newIntent.addFlags(Intent.FLAG_INCLUDE_STOPPED_PACKAGES);
|
|
116
|
-
newIntent.setAction(ACTION);
|
|
117
|
-
clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK
|
|
118
|
-
| Intent.FLAG_ACTIVITY_CLEAR_TOP
|
|
119
|
-
| Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
120
|
-
newIntent.putExtra(PUSH_PAYLOAD, message);
|
|
121
|
-
Utility.sendEventToListener(mContext, newIntent);
|
|
122
|
-
return PendingIntent.getActivity(
|
|
123
|
-
mContext, 1, clickIntent, getPendingIntentFlags());
|
|
124
|
-
} catch (Throwable e) {
|
|
125
|
-
Log.e(TAG, "createPendingIntent: error ",e );
|
|
126
|
-
}
|
|
127
|
-
return null;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
public static PendingIntent internalDeletePendingIntent(Context mContext) {
|
|
131
|
-
try {
|
|
132
|
-
// please use your launch activity here
|
|
133
|
-
Intent clickIntent = new Intent(mContext, MainActivity.class);
|
|
134
|
-
|
|
135
|
-
clickIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
|
136
|
-
return PendingIntent.getActivity(mContext, 1, clickIntent,
|
|
137
|
-
getPendingIntentFlags());
|
|
138
|
-
}catch (Throwable t){
|
|
139
|
-
Log.e(TAG, "deletePendingIntent: error ",t );
|
|
140
|
-
}
|
|
141
|
-
return null;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
private static int getPendingIntentFlags(){
|
|
145
|
-
int flag;
|
|
146
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
147
|
-
flag = PendingIntent.FLAG_UPDATE_CURRENT | PendingIntent.FLAG_MUTABLE;
|
|
148
|
-
} else {
|
|
149
|
-
flag = PendingIntent.FLAG_UPDATE_CURRENT;
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
return flag;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
private boolean checkIfPayloadHaveExternalUrl(RemoteMessage message) {
|
|
156
|
-
Map<String, String> map = message.getData();
|
|
157
|
-
|
|
158
|
-
try {
|
|
159
|
-
if (map != null) {
|
|
160
|
-
String messageStr = map.get(MESSAGE);
|
|
161
|
-
if (messageStr != null && messageStr.length() > 0) {
|
|
162
|
-
JSONObject messageObj = new JSONObject(messageStr);
|
|
163
|
-
String type = messageObj.optString(EXTERNAL_TYPE);
|
|
164
|
-
if (type.equalsIgnoreCase(DEEPLINK)) {
|
|
165
|
-
return false;
|
|
166
|
-
}
|
|
167
|
-
if (type.equalsIgnoreCase(LANDING_PAGE)) {
|
|
168
|
-
return true;
|
|
169
|
-
}
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
} catch (Throwable t) {
|
|
173
|
-
Log.e(TAG, "checkIfPayloadHaveExternalUrl: error ", t);
|
|
174
|
-
}
|
|
175
|
-
return false;
|
|
63
|
+
public void onNewToken(@NonNull String token) {
|
|
64
|
+
super.onNewToken(token);
|
|
65
|
+
appICEPushHandler.onNewToken(token, getApplicationContext());
|
|
176
66
|
}
|
|
177
|
-
}
|
|
67
|
+
}
|