pushwoosh-cordova-plugin 6.0.1 → 6.1.1
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/{MIT-LICENSE.txt → LICENSE.md} +0 -0
- package/README.md +20 -32
- package/README_PGB.md +32 -0
- package/package.json +1 -1
- package/package_pgb.json +29 -0
- package/plugin.xml +71 -82
- package/src/android/src/com/pushwoosh/plugin/internal/PhonegapPluginProvider.java +22 -0
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/CustomFirebaseMessagingService.java +29 -0
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/InboxUiStyleManager.java +136 -0
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushNotifications.java +365 -387
- package/src/android/src/com/pushwoosh/plugin/pushnotifications/PushwooshNotificationServiceExtension.java +38 -0
- package/src/ios/PWBackward.h +25 -0
- package/src/ios/PWBackward.m +53 -0
- package/src/ios/PushNotification.m +409 -147
- package/src/ios/Pushwoosh.framework/Modules/module.modulemap +6 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWAppDelegate.h +20 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWGDPRManager.h +46 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInAppManager.h +174 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInbox.h +147 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWInlineInAppView.h +26 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWLog.h +23 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWMessaging.h +20 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWNotificationExtensionManager.h +33 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaManager.h +118 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PWRichMediaStyle.h +122 -0
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/PushNotificationManager.h +263 -151
- package/src/ios/Pushwoosh.framework/Versions/A/Headers/Pushwoosh.h +525 -0
- package/src/ios/Pushwoosh.framework/Versions/A/libPushwoosh.a +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/Info.plist +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/PWIInboxAttachmentViewController.nib +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/PWIInboxMessageViewCell.nib +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/PWIInboxViewController.nib +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/errorMessage@2x.png +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/inbox_icon.png +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/noMessage@2x.png +0 -0
- package/src/ios/PushwooshInboxBundle.bundle/unread.png +0 -0
- package/src/ios/PushwooshInboxUI.framework/Modules/module.modulemap +6 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxStyle.h +122 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PWIInboxUI.h +39 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/Headers/PushwooshInboxUI.h +19 -0
- package/src/ios/PushwooshInboxUI.framework/Versions/A/libPushwooshInboxUI.a +0 -0
- package/src/windows/PushSDK/Newtonsoft.Json.dll +0 -0
- package/src/windows/PushSDK/PushSDK.winmd +0 -0
- package/src/windows/PushwooshPluginProxy.js +88 -74
- package/src/wp8/PushNotification.cs +14 -0
- package/src/wp8/PushSDK/PushSDK.dll +0 -0
- package/www/PushNotification.js +179 -45
- package/Documentation/files/PushNotification-js.html +0 -157
- package/Documentation/index/Classes.html +0 -33
- package/Documentation/index/Functions.html +0 -61
- package/Documentation/index/General.html +0 -65
- package/Documentation/index.html +0 -1
- package/Documentation/javascript/main.js +0 -841
- package/Documentation/javascript/prettify.js +0 -1526
- package/Documentation/javascript/searchdata.js +0 -92
- package/Documentation/search/ClassesP.html +0 -20
- package/Documentation/search/FunctionsA.html +0 -20
- package/Documentation/search/FunctionsC.html +0 -20
- package/Documentation/search/FunctionsG.html +0 -20
- package/Documentation/search/FunctionsO.html +0 -20
- package/Documentation/search/FunctionsP.html +0 -20
- package/Documentation/search/FunctionsR.html +0 -20
- package/Documentation/search/FunctionsS.html +0 -20
- package/Documentation/search/FunctionsU.html +0 -20
- package/Documentation/search/GeneralA.html +0 -20
- package/Documentation/search/GeneralC.html +0 -20
- package/Documentation/search/GeneralF.html +0 -20
- package/Documentation/search/GeneralG.html +0 -20
- package/Documentation/search/GeneralO.html +0 -20
- package/Documentation/search/GeneralP.html +0 -20
- package/Documentation/search/GeneralR.html +0 -20
- package/Documentation/search/GeneralS.html +0 -20
- package/Documentation/search/GeneralU.html +0 -20
- package/Documentation/search/NoResults.html +0 -15
- package/Documentation/styles/main.css +0 -828
- package/VERSION.md +0 -132
- package/push.gradle +0 -21
- package/src/ios/Pushwoosh.framework/Versions/A/Pushwoosh +0 -0
|
@@ -10,53 +10,65 @@
|
|
|
10
10
|
|
|
11
11
|
package com.pushwoosh.plugin.pushnotifications;
|
|
12
12
|
|
|
13
|
-
import java.lang.annotation.Retention;
|
|
14
|
-
import java.lang.reflect.Method;
|
|
15
|
-
import java.util.ArrayList;
|
|
16
|
-
import java.util.Arrays;
|
|
17
|
-
import java.util.HashMap;
|
|
18
|
-
import java.util.Iterator;
|
|
19
|
-
import java.util.List;
|
|
20
|
-
import java.util.Map;
|
|
21
|
-
|
|
22
|
-
import android.content.BroadcastReceiver;
|
|
23
|
-
import android.content.Context;
|
|
24
13
|
import android.content.Intent;
|
|
25
|
-
import android.content.IntentFilter;
|
|
26
14
|
import android.os.Bundle;
|
|
27
|
-
import android.
|
|
28
|
-
import android.
|
|
29
|
-
|
|
30
|
-
import
|
|
15
|
+
import android.os.Handler;
|
|
16
|
+
import android.os.Looper;
|
|
17
|
+
import androidx.annotation.NonNull;
|
|
18
|
+
import androidx.core.app.NotificationManagerCompat;
|
|
19
|
+
import android.webkit.JavascriptInterface;
|
|
20
|
+
|
|
21
|
+
import com.pushwoosh.GDPRManager;
|
|
22
|
+
import com.pushwoosh.Pushwoosh;
|
|
23
|
+
import com.pushwoosh.badge.PushwooshBadge;
|
|
24
|
+
import com.pushwoosh.exception.GetTagsException;
|
|
25
|
+
import com.pushwoosh.exception.PushwooshException;
|
|
26
|
+
import com.pushwoosh.exception.RegisterForPushNotificationsException;
|
|
27
|
+
import com.pushwoosh.exception.UnregisterForPushNotificationException;
|
|
28
|
+
import com.pushwoosh.function.Callback;
|
|
29
|
+
import com.pushwoosh.function.Result;
|
|
30
|
+
import com.pushwoosh.inapp.PushwooshInApp;
|
|
31
|
+
import com.pushwoosh.inbox.ui.presentation.view.activity.InboxActivity;
|
|
32
|
+
import com.pushwoosh.internal.platform.utils.GeneralUtils;
|
|
31
33
|
import com.pushwoosh.internal.utils.PWLog;
|
|
34
|
+
import com.pushwoosh.notification.LocalNotification;
|
|
35
|
+
import com.pushwoosh.notification.LocalNotificationReceiver;
|
|
36
|
+
import com.pushwoosh.notification.PushMessage;
|
|
37
|
+
import com.pushwoosh.notification.PushwooshNotificationSettings;
|
|
32
38
|
import com.pushwoosh.notification.SoundType;
|
|
33
39
|
import com.pushwoosh.notification.VibrateType;
|
|
34
|
-
import com.pushwoosh.
|
|
35
|
-
import com.pushwoosh.
|
|
36
|
-
import com.pushwoosh.BaseRegistrationReceiver;
|
|
37
|
-
import com.pushwoosh.SendPushTagsCallBack;
|
|
38
|
-
import com.pushwoosh.internal.utils.GeneralUtils;
|
|
39
|
-
import com.pushwoosh.internal.utils.JsonUtils;
|
|
40
|
-
import com.pushwoosh.inapp.InAppFacade;
|
|
40
|
+
import com.pushwoosh.tags.Tags;
|
|
41
|
+
import com.pushwoosh.tags.TagsBundle;
|
|
41
42
|
|
|
42
43
|
import org.apache.cordova.CallbackContext;
|
|
43
44
|
import org.apache.cordova.CordovaPlugin;
|
|
45
|
+
import org.apache.cordova.CordovaWebView;
|
|
44
46
|
import org.json.JSONArray;
|
|
45
47
|
import org.json.JSONException;
|
|
46
48
|
import org.json.JSONObject;
|
|
47
49
|
|
|
50
|
+
import java.lang.annotation.Retention;
|
|
51
|
+
import java.lang.reflect.Method;
|
|
52
|
+
import java.util.ArrayList;
|
|
53
|
+
import java.util.Arrays;
|
|
54
|
+
import java.util.HashMap;
|
|
55
|
+
import java.util.List;
|
|
56
|
+
import java.util.Map;
|
|
57
|
+
import java.util.concurrent.atomic.AtomicBoolean;
|
|
58
|
+
|
|
48
59
|
import static java.lang.annotation.RetentionPolicy.RUNTIME;
|
|
49
60
|
|
|
50
|
-
public class PushNotifications extends CordovaPlugin
|
|
51
|
-
|
|
52
|
-
private static final
|
|
61
|
+
public class PushNotifications extends CordovaPlugin {
|
|
62
|
+
public static final String TAG = "CordovaPlugin";
|
|
63
|
+
private static final Object sStartPushLock = new Object();
|
|
53
64
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
JSONObject startPushData = null;
|
|
65
|
+
private static String sStartPushData;
|
|
66
|
+
private static String sReceivedPushData;
|
|
57
67
|
|
|
58
|
-
|
|
59
|
-
|
|
68
|
+
private static AtomicBoolean sAppReady = new AtomicBoolean();
|
|
69
|
+
private static PushNotifications sInstance;
|
|
70
|
+
|
|
71
|
+
private final HashMap<String, CallbackContext> callbackIds = new HashMap<String, CallbackContext>();
|
|
60
72
|
|
|
61
73
|
private static final Map<String, Method> exportedMethods;
|
|
62
74
|
|
|
@@ -65,8 +77,8 @@ public class PushNotifications extends CordovaPlugin
|
|
|
65
77
|
|
|
66
78
|
}
|
|
67
79
|
|
|
68
|
-
|
|
69
|
-
{
|
|
80
|
+
|
|
81
|
+
static {
|
|
70
82
|
HashMap<String, Method> methods = new HashMap<String, Method>();
|
|
71
83
|
|
|
72
84
|
final List<Method> allMethods = new ArrayList<Method>(Arrays.asList(PushNotifications.class.getDeclaredMethods()));
|
|
@@ -79,116 +91,30 @@ public class PushNotifications extends CordovaPlugin
|
|
|
79
91
|
exportedMethods = methods;
|
|
80
92
|
}
|
|
81
93
|
|
|
82
|
-
|
|
83
|
-
* Called when the activity receives a new intent.
|
|
84
|
-
*/
|
|
85
|
-
public void onNewIntent(Intent intent)
|
|
86
|
-
{
|
|
87
|
-
super.onNewIntent(intent);
|
|
94
|
+
private final Handler handler = new Handler(Looper.getMainLooper());
|
|
88
95
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
private BroadcastReceiver mRegistrationReceiver = new BaseRegistrationReceiver()
|
|
94
|
-
{
|
|
95
|
-
@Override
|
|
96
|
-
public void onRegisterActionReceive(Context context, Intent intent)
|
|
97
|
-
{
|
|
98
|
-
checkMessage(intent);
|
|
99
|
-
}
|
|
100
|
-
};
|
|
101
|
-
|
|
102
|
-
private BroadcastReceiver mPushReceiver = new BasePushMessageReceiver()
|
|
103
|
-
{
|
|
104
|
-
@Override
|
|
105
|
-
protected void onMessageReceive(Intent intent)
|
|
106
|
-
{
|
|
107
|
-
doOnMessageReceive(intent.getStringExtra(JSON_DATA_KEY));
|
|
108
|
-
}
|
|
109
|
-
};
|
|
110
|
-
|
|
111
|
-
//Registration of the receivers
|
|
112
|
-
public void registerReceivers()
|
|
113
|
-
{
|
|
114
|
-
if (receiversRegistered)
|
|
115
|
-
return;
|
|
116
|
-
|
|
117
|
-
IntentFilter intentFilter = new IntentFilter(cordova.getActivity().getPackageName() + ".action.PUSH_MESSAGE_RECEIVE");
|
|
118
|
-
|
|
119
|
-
//comment this code out if you would like to receive the notifications in the notifications center when the app is in foreground
|
|
120
|
-
if (broadcastPush)
|
|
121
|
-
cordova.getActivity().registerReceiver(mPushReceiver, intentFilter);
|
|
122
|
-
|
|
123
|
-
//registration receiver
|
|
124
|
-
cordova.getActivity().registerReceiver(mRegistrationReceiver, new IntentFilter(cordova.getActivity().getPackageName() + "." + PushManager.REGISTER_BROAD_CAST_ACTION));
|
|
125
|
-
|
|
126
|
-
receiversRegistered = true;
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
public void unregisterReceivers()
|
|
130
|
-
{
|
|
131
|
-
if (!receiversRegistered)
|
|
132
|
-
return;
|
|
133
|
-
|
|
134
|
-
try
|
|
135
|
-
{
|
|
136
|
-
cordova.getActivity().unregisterReceiver(mPushReceiver);
|
|
137
|
-
}
|
|
138
|
-
catch (Exception e)
|
|
139
|
-
{
|
|
140
|
-
// pass. for some reason Phonegap call this method before onResume. Not Android lifecycle style...
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
try
|
|
144
|
-
{
|
|
145
|
-
cordova.getActivity().unregisterReceiver(mRegistrationReceiver);
|
|
146
|
-
}
|
|
147
|
-
catch (Exception e)
|
|
148
|
-
{
|
|
149
|
-
//pass through
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
receiversRegistered = false;
|
|
96
|
+
public PushNotifications () {
|
|
97
|
+
sInstance = this;
|
|
98
|
+
sAppReady.set(false);
|
|
153
99
|
}
|
|
154
100
|
|
|
155
101
|
@Override
|
|
156
|
-
public void
|
|
157
|
-
{
|
|
158
|
-
super.onResume(multitasking);
|
|
159
|
-
registerReceivers();
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
@Override
|
|
163
|
-
public void onPause(boolean multitasking)
|
|
164
|
-
{
|
|
165
|
-
super.onPause(multitasking);
|
|
166
|
-
unregisterReceivers();
|
|
167
|
-
}
|
|
168
|
-
|
|
169
|
-
/**
|
|
170
|
-
* The final call you receive before your activity is destroyed.
|
|
171
|
-
*/
|
|
172
|
-
public void onDestroy()
|
|
173
|
-
{
|
|
102
|
+
public void onDestroy() {
|
|
174
103
|
super.onDestroy();
|
|
104
|
+
PWLog.noise("OnDestroy");
|
|
105
|
+
sAppReady.set(false);
|
|
175
106
|
}
|
|
176
107
|
|
|
177
|
-
private JSONObject getPushFromIntent(Intent intent)
|
|
178
|
-
{
|
|
108
|
+
private JSONObject getPushFromIntent(Intent intent) {
|
|
179
109
|
if (null == intent)
|
|
180
110
|
return null;
|
|
181
111
|
|
|
182
|
-
if (intent.hasExtra(
|
|
183
|
-
|
|
184
|
-
String pushString = intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT);
|
|
112
|
+
if (intent.hasExtra(Pushwoosh.PUSH_RECEIVE_EVENT)) {
|
|
113
|
+
String pushString = intent.getExtras().getString(Pushwoosh.PUSH_RECEIVE_EVENT);
|
|
185
114
|
JSONObject pushObject = null;
|
|
186
|
-
try
|
|
187
|
-
{
|
|
115
|
+
try {
|
|
188
116
|
pushObject = new JSONObject(pushString);
|
|
189
|
-
}
|
|
190
|
-
catch (JSONException e)
|
|
191
|
-
{
|
|
117
|
+
} catch (JSONException e) {
|
|
192
118
|
PWLog.error(TAG, "Failed to parse push notification", e);
|
|
193
119
|
}
|
|
194
120
|
|
|
@@ -198,128 +124,92 @@ public class PushNotifications extends CordovaPlugin
|
|
|
198
124
|
return null;
|
|
199
125
|
}
|
|
200
126
|
|
|
201
|
-
private void checkMessage(Intent intent)
|
|
202
|
-
{
|
|
203
|
-
if (null != intent)
|
|
204
|
-
{
|
|
205
|
-
if (intent.hasExtra(PushManager.PUSH_RECEIVE_EVENT))
|
|
206
|
-
{
|
|
207
|
-
doOnMessageReceive(intent.getExtras().getString(PushManager.PUSH_RECEIVE_EVENT));
|
|
208
|
-
}
|
|
209
|
-
else if (intent.hasExtra(PushManager.REGISTER_EVENT))
|
|
210
|
-
{
|
|
211
|
-
doOnRegistered(intent.getExtras().getString(PushManager.REGISTER_EVENT));
|
|
212
|
-
}
|
|
213
|
-
else if (intent.hasExtra(PushManager.UNREGISTER_EVENT))
|
|
214
|
-
{
|
|
215
|
-
doOnUnregistered(intent.getExtras().getString(PushManager.UNREGISTER_EVENT));
|
|
216
|
-
}
|
|
217
|
-
else if (intent.hasExtra(PushManager.REGISTER_ERROR_EVENT))
|
|
218
|
-
{
|
|
219
|
-
doOnRegisteredError(intent.getExtras().getString(PushManager.REGISTER_ERROR_EVENT));
|
|
220
|
-
}
|
|
221
|
-
else if (intent.hasExtra(PushManager.UNREGISTER_ERROR_EVENT))
|
|
222
|
-
{
|
|
223
|
-
doOnUnregisteredError(intent.getExtras().getString(PushManager.UNREGISTER_ERROR_EVENT));
|
|
224
|
-
}
|
|
225
|
-
|
|
226
|
-
intent.removeExtra(PushManager.PUSH_RECEIVE_EVENT);
|
|
227
|
-
intent.removeExtra(PushManager.REGISTER_EVENT);
|
|
228
|
-
intent.removeExtra(PushManager.UNREGISTER_EVENT);
|
|
229
|
-
intent.removeExtra(PushManager.REGISTER_ERROR_EVENT);
|
|
230
|
-
intent.removeExtra(PushManager.UNREGISTER_ERROR_EVENT);
|
|
231
|
-
|
|
232
|
-
cordova.getActivity().setIntent(intent);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
127
|
@CordovaMethod
|
|
237
|
-
private boolean onDeviceReady(JSONArray data, CallbackContext callbackContext)
|
|
238
|
-
{
|
|
128
|
+
private boolean onDeviceReady(JSONArray data, CallbackContext callbackContext) {
|
|
239
129
|
JSONObject params = null;
|
|
240
|
-
try
|
|
241
|
-
{
|
|
130
|
+
try {
|
|
242
131
|
params = data.getJSONObject(0);
|
|
243
|
-
}
|
|
244
|
-
catch (JSONException e)
|
|
245
|
-
{
|
|
132
|
+
} catch (JSONException e) {
|
|
246
133
|
PWLog.error(TAG, "No parameters has been passed to onDeviceReady function. Did you follow the guide correctly?", e);
|
|
247
134
|
return false;
|
|
248
135
|
}
|
|
249
136
|
|
|
250
|
-
try
|
|
251
|
-
{
|
|
252
|
-
String packageName = cordova.getActivity().getApplicationContext().getPackageName();
|
|
253
|
-
ApplicationInfo ai = cordova.getActivity().getPackageManager().getApplicationInfo(packageName, PackageManager.GET_META_DATA);
|
|
137
|
+
try {
|
|
254
138
|
|
|
255
|
-
|
|
256
|
-
|
|
139
|
+
String appid = null;
|
|
140
|
+
if (params.has("appid")) {
|
|
141
|
+
appid = params.getString("appid");
|
|
142
|
+
} else {
|
|
143
|
+
appid = params.getString("pw_appid");
|
|
144
|
+
}
|
|
257
145
|
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
catch (Exception e)
|
|
261
|
-
{
|
|
262
|
-
PWLog.error(TAG, "Failed to read AndroidManifest");
|
|
263
|
-
}
|
|
146
|
+
Pushwoosh.getInstance().setAppId(appid);
|
|
147
|
+
Pushwoosh.getInstance().setSenderId(params.getString("projectid"));
|
|
264
148
|
|
|
265
|
-
try
|
|
266
|
-
{
|
|
267
|
-
//make sure the receivers are on
|
|
268
|
-
registerReceivers();
|
|
269
149
|
|
|
270
|
-
|
|
150
|
+
synchronized (sStartPushLock) {
|
|
151
|
+
if (sReceivedPushData != null) {
|
|
152
|
+
doOnPushReceived(sReceivedPushData);
|
|
153
|
+
}
|
|
271
154
|
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
appid = params.getString("pw_appid");
|
|
155
|
+
if (sStartPushData != null) {
|
|
156
|
+
doOnPushOpened(sStartPushData);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
277
159
|
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
mPushManager.onStartup(cordova.getActivity());
|
|
281
|
-
}
|
|
282
|
-
catch (Exception e)
|
|
283
|
-
{
|
|
160
|
+
sAppReady.set(true);
|
|
161
|
+
} catch (Exception e) {
|
|
284
162
|
PWLog.error(TAG, "Missing pw_appid parameter. Did you follow the guide correctly?", e);
|
|
285
163
|
return false;
|
|
286
164
|
}
|
|
287
|
-
|
|
288
|
-
checkMessage(cordova.getActivity().getIntent());
|
|
289
165
|
return true;
|
|
290
166
|
}
|
|
291
167
|
|
|
292
168
|
@CordovaMethod
|
|
293
|
-
private boolean
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
169
|
+
private boolean additionalAuthorizationOptions(JSONArray data, CallbackContext callbackContext) {
|
|
170
|
+
// Stub, this is iOS only method
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
@CordovaMethod
|
|
174
|
+
private boolean registerDevice(JSONArray data, CallbackContext callbackContext) {
|
|
175
|
+
try {
|
|
297
176
|
callbackIds.put("registerDevice", callbackContext);
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
177
|
+
Pushwoosh.getInstance().registerForPushNotifications(new Callback<String, RegisterForPushNotificationsException>() {
|
|
178
|
+
@Override
|
|
179
|
+
public void process(@NonNull final Result<String, RegisterForPushNotificationsException> result) {
|
|
180
|
+
if (result.isSuccess()) {
|
|
181
|
+
doOnRegistered(result.getData());
|
|
182
|
+
} else if (result.getException() != null) {
|
|
183
|
+
doOnRegisteredError(result.getException().getMessage());
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
});
|
|
187
|
+
} catch (java.lang.RuntimeException e) {
|
|
188
|
+
callbackIds.remove("registerDevice");
|
|
303
189
|
PWLog.error(TAG, "registering for push notifications failed", e);
|
|
304
190
|
|
|
305
191
|
callbackContext.error(e.getMessage());
|
|
306
192
|
}
|
|
307
193
|
|
|
308
|
-
checkMessage(cordova.getActivity().getIntent());
|
|
309
194
|
return true;
|
|
310
195
|
}
|
|
311
196
|
|
|
312
197
|
@CordovaMethod
|
|
313
|
-
private boolean unregisterDevice(JSONArray data, CallbackContext callbackContext)
|
|
314
|
-
{
|
|
198
|
+
private boolean unregisterDevice(JSONArray data, CallbackContext callbackContext) {
|
|
315
199
|
callbackIds.put("unregisterDevice", callbackContext);
|
|
316
200
|
|
|
317
|
-
try
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
201
|
+
try {
|
|
202
|
+
Pushwoosh.getInstance().unregisterForPushNotifications(new Callback<String, UnregisterForPushNotificationException>() {
|
|
203
|
+
@Override
|
|
204
|
+
public void process(@NonNull final Result<String, UnregisterForPushNotificationException> result) {
|
|
205
|
+
if (result.isSuccess()) {
|
|
206
|
+
doOnUnregistered(result.getData());
|
|
207
|
+
} else if (result.getException() != null) {
|
|
208
|
+
doOnUnregisteredError(result.getException().getMessage());
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
});
|
|
212
|
+
} catch (Exception e) {
|
|
323
213
|
callbackIds.remove("unregisterDevice");
|
|
324
214
|
callbackContext.error(e.getMessage());
|
|
325
215
|
}
|
|
@@ -328,162 +218,68 @@ public class PushNotifications extends CordovaPlugin
|
|
|
328
218
|
}
|
|
329
219
|
|
|
330
220
|
@CordovaMethod
|
|
331
|
-
private boolean setTags(JSONArray data, final CallbackContext callbackContext)
|
|
332
|
-
{
|
|
221
|
+
private boolean setTags(JSONArray data, final CallbackContext callbackContext) {
|
|
333
222
|
JSONObject params;
|
|
334
|
-
try
|
|
335
|
-
{
|
|
223
|
+
try {
|
|
336
224
|
params = data.getJSONObject(0);
|
|
337
|
-
}
|
|
338
|
-
catch (JSONException e)
|
|
339
|
-
{
|
|
225
|
+
} catch (JSONException e) {
|
|
340
226
|
PWLog.error(TAG, "No tags information passed (missing parameters)", e);
|
|
341
227
|
return false;
|
|
342
228
|
}
|
|
343
|
-
|
|
344
|
-
@SuppressWarnings("unchecked")
|
|
345
|
-
Iterator<String> nameItr = params.keys();
|
|
346
|
-
Map<String, Object> paramsMap = new HashMap<String, Object>();
|
|
347
|
-
while (nameItr.hasNext())
|
|
348
|
-
{
|
|
349
|
-
try
|
|
350
|
-
{
|
|
351
|
-
String name = nameItr.next();
|
|
352
|
-
paramsMap.put(name, params.get(name));
|
|
353
|
-
}
|
|
354
|
-
catch (JSONException e)
|
|
355
|
-
{
|
|
356
|
-
PWLog.error(TAG, "Tag parameter is invalid", e);
|
|
357
|
-
return false;
|
|
358
|
-
}
|
|
359
|
-
}
|
|
360
|
-
|
|
361
229
|
callbackIds.put("setTags", callbackContext);
|
|
362
230
|
|
|
363
|
-
|
|
364
|
-
{
|
|
231
|
+
Pushwoosh.getInstance().sendTags(Tags.fromJson(params), new Callback<Void, PushwooshException>() {
|
|
365
232
|
@Override
|
|
366
|
-
public void
|
|
367
|
-
{
|
|
233
|
+
public void process(@NonNull final Result<Void, PushwooshException> result) {
|
|
368
234
|
CallbackContext callback = callbackIds.get("setTags");
|
|
369
|
-
if (callback == null)
|
|
235
|
+
if (callback == null) {
|
|
370
236
|
return;
|
|
237
|
+
}
|
|
371
238
|
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
public void onSentTagsError(Exception e)
|
|
378
|
-
{
|
|
379
|
-
CallbackContext callback = callbackIds.get("setTags");
|
|
380
|
-
if (callback == null)
|
|
381
|
-
return;
|
|
239
|
+
if(result.isSuccess()){
|
|
240
|
+
callback.success(new JSONObject());
|
|
241
|
+
} else if(result.getException()!=null){
|
|
242
|
+
callback.error(result.getException().getMessage());
|
|
243
|
+
}
|
|
382
244
|
|
|
383
|
-
callback.error(e.getMessage());
|
|
384
245
|
callbackIds.remove("setTags");
|
|
385
246
|
}
|
|
247
|
+
});
|
|
386
248
|
|
|
387
|
-
@Override
|
|
388
|
-
public void taskStarted()
|
|
389
|
-
{
|
|
390
|
-
}
|
|
391
|
-
}
|
|
392
|
-
|
|
393
|
-
PushManager.sendTags(cordova.getActivity(), paramsMap, new SendTagsListenerImpl());
|
|
394
249
|
return true;
|
|
395
250
|
}
|
|
396
251
|
|
|
397
252
|
@CordovaMethod
|
|
398
|
-
private boolean getTags(JSONArray data, final CallbackContext callbackContext)
|
|
399
|
-
{
|
|
253
|
+
private boolean getTags(JSONArray data, final CallbackContext callbackContext) {
|
|
400
254
|
callbackIds.put("getTags", callbackContext);
|
|
401
255
|
|
|
402
|
-
|
|
403
|
-
{
|
|
404
|
-
@Override
|
|
405
|
-
public void onTagsReceived(Map<String, Object> tags)
|
|
406
|
-
{
|
|
407
|
-
CallbackContext callback = callbackIds.get("getTags");
|
|
408
|
-
if (callback == null)
|
|
409
|
-
return;
|
|
410
|
-
|
|
411
|
-
callback.success(new JSONObject(tags));
|
|
412
|
-
callbackIds.remove("getTags");
|
|
413
|
-
}
|
|
414
|
-
|
|
256
|
+
Pushwoosh.getInstance().getTags(new Callback<TagsBundle, GetTagsException>() {
|
|
415
257
|
@Override
|
|
416
|
-
public void
|
|
417
|
-
{
|
|
258
|
+
public void process(@NonNull final Result<TagsBundle, GetTagsException> result) {
|
|
418
259
|
CallbackContext callback = callbackIds.get("getTags");
|
|
419
260
|
if (callback == null)
|
|
420
261
|
return;
|
|
421
262
|
|
|
422
|
-
|
|
263
|
+
if(result.isSuccess()) {
|
|
264
|
+
callback.success(result.getData().toJson());
|
|
265
|
+
} else {
|
|
266
|
+
callback.error(result.getException().getMessage());
|
|
267
|
+
}
|
|
423
268
|
callbackIds.remove("getTags");
|
|
424
269
|
}
|
|
425
|
-
}
|
|
426
|
-
|
|
427
|
-
PushManager.getTagsAsync(cordova.getActivity(), new GetTagsListenerImpl());
|
|
428
|
-
return true;
|
|
429
|
-
}
|
|
430
|
-
|
|
431
|
-
@CordovaMethod
|
|
432
|
-
private boolean getPushToken(JSONArray data, final CallbackContext callbackContext)
|
|
433
|
-
{
|
|
434
|
-
callbackContext.success(PushManager.getPushToken(cordova.getActivity()));
|
|
435
|
-
return true;
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
@CordovaMethod
|
|
439
|
-
private boolean getPushwooshHWID(JSONArray data, final CallbackContext callbackContext)
|
|
440
|
-
{
|
|
441
|
-
callbackContext.success(PushManager.getPushwooshHWID(cordova.getActivity()));
|
|
442
|
-
return true;
|
|
443
|
-
}
|
|
444
|
-
|
|
445
|
-
@CordovaMethod
|
|
446
|
-
private boolean startLocationTracking(JSONArray data, final CallbackContext callbackContext)
|
|
447
|
-
{
|
|
448
|
-
mPushManager.startTrackingGeoPushes();
|
|
449
|
-
return true;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
@CordovaMethod
|
|
453
|
-
private boolean stopLocationTracking(JSONArray data, final CallbackContext callbackContext)
|
|
454
|
-
{
|
|
455
|
-
mPushManager.stopTrackingGeoPushes();
|
|
270
|
+
});
|
|
456
271
|
return true;
|
|
457
272
|
}
|
|
458
273
|
|
|
459
274
|
@CordovaMethod
|
|
460
|
-
private boolean
|
|
461
|
-
|
|
462
|
-
mPushManager.startTrackingBeaconPushes();
|
|
275
|
+
private boolean getPushToken(JSONArray data, final CallbackContext callbackContext) {
|
|
276
|
+
callbackContext.success(Pushwoosh.getInstance().getPushToken());
|
|
463
277
|
return true;
|
|
464
278
|
}
|
|
465
279
|
|
|
466
280
|
@CordovaMethod
|
|
467
|
-
private boolean
|
|
468
|
-
|
|
469
|
-
mPushManager.stopTrackingBeaconPushes();
|
|
470
|
-
return true;
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
@CordovaMethod
|
|
474
|
-
private boolean setBeaconBackgroundMode(JSONArray data, final CallbackContext callbackContext)
|
|
475
|
-
{
|
|
476
|
-
try
|
|
477
|
-
{
|
|
478
|
-
boolean type = data.getBoolean(0);
|
|
479
|
-
PushManager.setBeaconBackgroundMode(cordova.getActivity(), type);
|
|
480
|
-
}
|
|
481
|
-
catch (Exception e)
|
|
482
|
-
{
|
|
483
|
-
PWLog.error(TAG, "No parameters passed (missing parameters)", e);
|
|
484
|
-
return false;
|
|
485
|
-
}
|
|
486
|
-
|
|
281
|
+
private boolean getPushwooshHWID(JSONArray data, final CallbackContext callbackContext) {
|
|
282
|
+
callbackContext.success(Pushwoosh.getInstance().getHwid());
|
|
487
283
|
return true;
|
|
488
284
|
}
|
|
489
285
|
|
|
@@ -505,17 +301,22 @@ public class PushNotifications extends CordovaPlugin
|
|
|
505
301
|
{
|
|
506
302
|
//config params: {msg:"message", seconds:30, userData:"optional"}
|
|
507
303
|
String message = params.getString("msg");
|
|
508
|
-
|
|
509
|
-
if (message == null
|
|
304
|
+
int seconds = params.getInt("seconds");
|
|
305
|
+
if (message == null) {
|
|
510
306
|
return false;
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
307
|
+
}
|
|
308
|
+
|
|
514
309
|
Bundle extras = new Bundle();
|
|
515
|
-
if (userData
|
|
516
|
-
extras.putString("u", userData);
|
|
517
|
-
|
|
518
|
-
|
|
310
|
+
if (params.has("userData")) {
|
|
311
|
+
extras.putString("u", params.getString("userData"));
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
LocalNotification notification = new LocalNotification.Builder()
|
|
315
|
+
.setMessage(message)
|
|
316
|
+
.setDelay(seconds)
|
|
317
|
+
.setExtras(extras)
|
|
318
|
+
.build();
|
|
319
|
+
Pushwoosh.getInstance().scheduleLocalNotification(notification);
|
|
519
320
|
}
|
|
520
321
|
catch (JSONException e)
|
|
521
322
|
{
|
|
@@ -529,22 +330,18 @@ public class PushNotifications extends CordovaPlugin
|
|
|
529
330
|
@CordovaMethod
|
|
530
331
|
private boolean clearLocalNotification(JSONArray data, final CallbackContext callbackContext)
|
|
531
332
|
{
|
|
532
|
-
|
|
333
|
+
LocalNotificationReceiver.cancelAll();
|
|
533
334
|
return true;
|
|
534
335
|
}
|
|
535
336
|
|
|
536
337
|
@CordovaMethod
|
|
537
338
|
private boolean getLaunchNotification(JSONArray data, final CallbackContext callbackContext)
|
|
538
339
|
{
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
if (launchNotification != null)
|
|
542
|
-
{
|
|
543
|
-
callbackContext.success(launchNotification);
|
|
544
|
-
}
|
|
545
|
-
else
|
|
546
|
-
{
|
|
340
|
+
PushMessage launchNotification = Pushwoosh.getInstance().getLaunchNotification();
|
|
341
|
+
if (launchNotification == null) {
|
|
547
342
|
callbackContext.success((String) null);
|
|
343
|
+
} else {
|
|
344
|
+
callbackContext.success(launchNotification.toJson().toString());
|
|
548
345
|
}
|
|
549
346
|
return true;
|
|
550
347
|
}
|
|
@@ -552,21 +349,21 @@ public class PushNotifications extends CordovaPlugin
|
|
|
552
349
|
@CordovaMethod
|
|
553
350
|
private boolean clearLaunchNotification(JSONArray data, final CallbackContext callbackContext)
|
|
554
351
|
{
|
|
555
|
-
|
|
352
|
+
Pushwoosh.getInstance().clearLaunchNotification();
|
|
556
353
|
return true;
|
|
557
354
|
}
|
|
558
355
|
|
|
559
356
|
@CordovaMethod
|
|
560
357
|
private boolean setMultiNotificationMode(JSONArray data, final CallbackContext callbackContext)
|
|
561
358
|
{
|
|
562
|
-
|
|
359
|
+
PushwooshNotificationSettings.setMultiNotificationMode(true);
|
|
563
360
|
return true;
|
|
564
361
|
}
|
|
565
362
|
|
|
566
363
|
@CordovaMethod
|
|
567
364
|
private boolean setSingleNotificationMode(JSONArray data, final CallbackContext callbackContext)
|
|
568
365
|
{
|
|
569
|
-
|
|
366
|
+
PushwooshNotificationSettings.setMultiNotificationMode(false);
|
|
570
367
|
return true;
|
|
571
368
|
}
|
|
572
369
|
|
|
@@ -579,7 +376,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
579
376
|
if (type == null)
|
|
580
377
|
return false;
|
|
581
378
|
|
|
582
|
-
|
|
379
|
+
PushwooshNotificationSettings.setSoundNotificationType(SoundType.fromInt(type));
|
|
583
380
|
}
|
|
584
381
|
catch (Exception e)
|
|
585
382
|
{
|
|
@@ -599,7 +396,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
599
396
|
if (type == null)
|
|
600
397
|
return false;
|
|
601
398
|
|
|
602
|
-
|
|
399
|
+
PushwooshNotificationSettings.setVibrateNotificationType(VibrateType.fromInt(type));
|
|
603
400
|
}
|
|
604
401
|
catch (Exception e)
|
|
605
402
|
{
|
|
@@ -616,7 +413,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
616
413
|
try
|
|
617
414
|
{
|
|
618
415
|
boolean type = (boolean) data.getBoolean(0);
|
|
619
|
-
|
|
416
|
+
PushwooshNotificationSettings.setLightScreenOnNotification(type);
|
|
620
417
|
}
|
|
621
418
|
catch (Exception e)
|
|
622
419
|
{
|
|
@@ -633,7 +430,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
633
430
|
try
|
|
634
431
|
{
|
|
635
432
|
boolean type = (boolean) data.getBoolean(0);
|
|
636
|
-
|
|
433
|
+
PushwooshNotificationSettings.setEnableLED(type);
|
|
637
434
|
}
|
|
638
435
|
catch (Exception e)
|
|
639
436
|
{
|
|
@@ -654,7 +451,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
654
451
|
return false;
|
|
655
452
|
|
|
656
453
|
int colorLed = GeneralUtils.parseColor(colorString);
|
|
657
|
-
|
|
454
|
+
PushwooshNotificationSettings.setColorLED(colorLed);
|
|
658
455
|
}
|
|
659
456
|
catch (Exception e)
|
|
660
457
|
{
|
|
@@ -668,7 +465,12 @@ public class PushNotifications extends CordovaPlugin
|
|
|
668
465
|
@CordovaMethod
|
|
669
466
|
private boolean getPushHistory(JSONArray data, final CallbackContext callbackContext)
|
|
670
467
|
{
|
|
671
|
-
|
|
468
|
+
List<PushMessage> pushMessageHistory = Pushwoosh.getInstance().getPushHistory();
|
|
469
|
+
List<String> pushHistory = new ArrayList<String>();
|
|
470
|
+
|
|
471
|
+
for (PushMessage pushMessage: pushMessageHistory){
|
|
472
|
+
pushHistory.add(pushMessage.toJson().toString());
|
|
473
|
+
}
|
|
672
474
|
callbackContext.success(new JSONArray(pushHistory));
|
|
673
475
|
return true;
|
|
674
476
|
}
|
|
@@ -676,14 +478,14 @@ public class PushNotifications extends CordovaPlugin
|
|
|
676
478
|
@CordovaMethod
|
|
677
479
|
private boolean clearPushHistory(JSONArray data, final CallbackContext callbackContext)
|
|
678
480
|
{
|
|
679
|
-
|
|
481
|
+
Pushwoosh.getInstance().clearPushHistory();
|
|
680
482
|
return true;
|
|
681
483
|
}
|
|
682
484
|
|
|
683
485
|
@CordovaMethod
|
|
684
486
|
private boolean clearNotificationCenter(JSONArray data, final CallbackContext callbackContext)
|
|
685
487
|
{
|
|
686
|
-
|
|
488
|
+
NotificationManagerCompat.from(cordova.getActivity()).cancelAll();
|
|
687
489
|
return true;
|
|
688
490
|
}
|
|
689
491
|
|
|
@@ -693,10 +495,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
693
495
|
try
|
|
694
496
|
{
|
|
695
497
|
Integer badgeNumber = data.getJSONObject(0).getInt("badge");
|
|
696
|
-
|
|
697
|
-
return false;
|
|
698
|
-
|
|
699
|
-
mPushManager.setBadgeNumber(badgeNumber);
|
|
498
|
+
PushwooshBadge.setBadgeNumber(badgeNumber);
|
|
700
499
|
}
|
|
701
500
|
catch (JSONException e)
|
|
702
501
|
{
|
|
@@ -709,7 +508,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
709
508
|
@CordovaMethod
|
|
710
509
|
private boolean getApplicationIconBadgeNumber(JSONArray data, final CallbackContext callbackContext)
|
|
711
510
|
{
|
|
712
|
-
Integer badgeNumber
|
|
511
|
+
Integer badgeNumber = PushwooshBadge.getBadgeNumber();
|
|
713
512
|
callbackContext.success(badgeNumber);
|
|
714
513
|
return true;
|
|
715
514
|
}
|
|
@@ -720,9 +519,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
720
519
|
try
|
|
721
520
|
{
|
|
722
521
|
Integer badgeNumber = data.getJSONObject(0).getInt("badge");
|
|
723
|
-
|
|
724
|
-
return false;
|
|
725
|
-
mPushManager.addBadgeNumber(badgeNumber);
|
|
522
|
+
PushwooshBadge.addBadgeNumber(badgeNumber);
|
|
726
523
|
}
|
|
727
524
|
catch (JSONException e)
|
|
728
525
|
{
|
|
@@ -738,7 +535,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
738
535
|
try
|
|
739
536
|
{
|
|
740
537
|
String userId = data.getString(0);
|
|
741
|
-
|
|
538
|
+
PushwooshInApp.getInstance().setUserId(userId);
|
|
742
539
|
}
|
|
743
540
|
catch (JSONException e)
|
|
744
541
|
{
|
|
@@ -754,7 +551,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
754
551
|
{
|
|
755
552
|
String event = data.getString(0);
|
|
756
553
|
JSONObject attributes = data.getJSONObject(1);
|
|
757
|
-
|
|
554
|
+
PushwooshInApp.getInstance().postEvent(event, Tags.fromJson(attributes));
|
|
758
555
|
}
|
|
759
556
|
catch (JSONException e)
|
|
760
557
|
{
|
|
@@ -768,7 +565,7 @@ public class PushNotifications extends CordovaPlugin
|
|
|
768
565
|
{
|
|
769
566
|
try
|
|
770
567
|
{
|
|
771
|
-
String enabled =
|
|
568
|
+
String enabled = PushwooshNotificationSettings.areNotificationsEnabled() ? "1" : "0";
|
|
772
569
|
JSONObject result = new JSONObject();
|
|
773
570
|
result.put("enabled", enabled);
|
|
774
571
|
callbackContext.success(result);
|
|
@@ -781,6 +578,91 @@ public class PushNotifications extends CordovaPlugin
|
|
|
781
578
|
return true;
|
|
782
579
|
}
|
|
783
580
|
|
|
581
|
+
@CordovaMethod
|
|
582
|
+
private boolean presentInboxUI(JSONArray data, final CallbackContext callbackContext) {
|
|
583
|
+
if (data.length() > 0)
|
|
584
|
+
InboxUiStyleManager.setStyle(this.cordova.getActivity(), data.optJSONObject(0));
|
|
585
|
+
this.cordova.getActivity().startActivity(new Intent(this.cordova.getActivity(), InboxActivity.class));
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
@CordovaMethod
|
|
590
|
+
public boolean showGDPRConsentUI(JSONArray data, final CallbackContext callbackContext){
|
|
591
|
+
GDPRManager.getInstance().showGDPRConsentUI();
|
|
592
|
+
return true;
|
|
593
|
+
}
|
|
594
|
+
|
|
595
|
+
@CordovaMethod
|
|
596
|
+
public boolean showGDPRDeletionUI(JSONArray data, final CallbackContext callbackContext){
|
|
597
|
+
GDPRManager.getInstance().showGDPRDeletionUI();
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
|
|
601
|
+
@CordovaMethod
|
|
602
|
+
public boolean isDeviceDataRemoved(JSONArray data, final CallbackContext callbackContext){
|
|
603
|
+
boolean removed = GDPRManager.getInstance().isDeviceDataRemoved();
|
|
604
|
+
callbackContext.success(removed ? 1 : 0);
|
|
605
|
+
return true;
|
|
606
|
+
}
|
|
607
|
+
|
|
608
|
+
@CordovaMethod
|
|
609
|
+
public boolean isCommunicationEnabled(JSONArray data, final CallbackContext callbackContext){
|
|
610
|
+
boolean enabled = GDPRManager.getInstance().isCommunicationEnabled();
|
|
611
|
+
callbackContext.success(enabled ? 1 : 0);
|
|
612
|
+
return true;
|
|
613
|
+
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
@CordovaMethod
|
|
617
|
+
public boolean isAvailableGDPR(JSONArray data, final CallbackContext callbackContext){
|
|
618
|
+
boolean isAvailableGDPR = GDPRManager.getInstance().isAvailable();
|
|
619
|
+
callbackContext.success(isAvailableGDPR ? 1 : 0);
|
|
620
|
+
return true;
|
|
621
|
+
}
|
|
622
|
+
|
|
623
|
+
@CordovaMethod
|
|
624
|
+
public boolean removeAllDeviceData(JSONArray data, final CallbackContext callbackContext){
|
|
625
|
+
GDPRManager.getInstance().removeAllDeviceData(new Callback<Void, PushwooshException>() {
|
|
626
|
+
@Override
|
|
627
|
+
public void process(@NonNull Result<Void, PushwooshException> result) {
|
|
628
|
+
if(result.isSuccess()){
|
|
629
|
+
callbackContext.success();
|
|
630
|
+
}else {
|
|
631
|
+
callbackContext.error(result.getException().getMessage());
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
});
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
|
|
638
|
+
@CordovaMethod
|
|
639
|
+
public boolean setCommunicationEnabled(JSONArray data, final CallbackContext callbackContext){
|
|
640
|
+
try {
|
|
641
|
+
boolean enable = data.getBoolean(0);
|
|
642
|
+
GDPRManager.getInstance().setCommunicationEnabled(enable, new Callback<Void, PushwooshException>() {
|
|
643
|
+
@Override
|
|
644
|
+
public void process(@NonNull Result<Void, PushwooshException> result) {
|
|
645
|
+
if(result.isSuccess()){
|
|
646
|
+
callbackContext.success();
|
|
647
|
+
}else {
|
|
648
|
+
callbackContext.error(result.getException().getMessage());
|
|
649
|
+
}
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
return true;
|
|
653
|
+
} catch (JSONException e) {
|
|
654
|
+
e.printStackTrace();
|
|
655
|
+
}
|
|
656
|
+
return false;
|
|
657
|
+
}
|
|
658
|
+
|
|
659
|
+
@CordovaMethod
|
|
660
|
+
public boolean enableHuaweiPushNotifications(JSONArray data, final CallbackContext callbackContext) {
|
|
661
|
+
Pushwoosh.getInstance().enableHuaweiPushNotifications();
|
|
662
|
+
return true;
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
|
|
784
666
|
@Override
|
|
785
667
|
public boolean execute(String action, JSONArray data, CallbackContext callbackId)
|
|
786
668
|
{
|
|
@@ -855,10 +737,27 @@ public class PushNotifications extends CordovaPlugin
|
|
|
855
737
|
callbackIds.remove("unregisterDevice");
|
|
856
738
|
}
|
|
857
739
|
|
|
858
|
-
private void
|
|
740
|
+
private void doOnPushOpened(String notification)
|
|
859
741
|
{
|
|
860
|
-
PWLog.debug(TAG, "
|
|
742
|
+
PWLog.debug(TAG, "push opened: " + notification);
|
|
861
743
|
|
|
744
|
+
String jsStatement = String.format("cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").notificationCallback(%s);", convertNotification(notification));
|
|
745
|
+
evalJs(jsStatement);
|
|
746
|
+
sStartPushData = null;
|
|
747
|
+
}
|
|
748
|
+
|
|
749
|
+
public void doOnPushReceived(String notification)
|
|
750
|
+
{
|
|
751
|
+
PWLog.debug(TAG, "push received: " + notification);
|
|
752
|
+
|
|
753
|
+
String jsStatement = String.format("cordova.require(\"pushwoosh-cordova-plugin.PushNotification\").pushReceivedCallback(%s);", convertNotification(notification));
|
|
754
|
+
evalJs(jsStatement);
|
|
755
|
+
|
|
756
|
+
sReceivedPushData = null;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
private String convertNotification(String notification)
|
|
760
|
+
{
|
|
862
761
|
JSONObject unifiedNotification = new JSONObject();
|
|
863
762
|
|
|
864
763
|
try
|
|
@@ -880,16 +779,95 @@ public class PushNotifications extends CordovaPlugin
|
|
|
880
779
|
PWLog.error(TAG, "push message parsing failed", e);
|
|
881
780
|
}
|
|
882
781
|
|
|
883
|
-
|
|
884
|
-
//webView.sendJavascript(jsStatement);
|
|
782
|
+
String result = unifiedNotification.toString();
|
|
885
783
|
|
|
886
|
-
|
|
784
|
+
// wrap special characters
|
|
785
|
+
result = result.replace("%", "%\"+\"");
|
|
786
|
+
|
|
787
|
+
return result;
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
private void evalJs(String statement)
|
|
791
|
+
{
|
|
792
|
+
final String url = "javascript:" + statement;
|
|
793
|
+
|
|
794
|
+
handler.post(new Runnable()
|
|
887
795
|
{
|
|
888
796
|
@Override
|
|
889
797
|
public void run()
|
|
890
798
|
{
|
|
891
|
-
|
|
799
|
+
try
|
|
800
|
+
{
|
|
801
|
+
webView.loadUrl(url);
|
|
802
|
+
}
|
|
803
|
+
catch (Exception e)
|
|
804
|
+
{
|
|
805
|
+
PWLog.exception(e);
|
|
806
|
+
}
|
|
892
807
|
}
|
|
893
808
|
});
|
|
894
809
|
}
|
|
810
|
+
|
|
811
|
+
|
|
812
|
+
static void openPush(String pushData) {
|
|
813
|
+
try {
|
|
814
|
+
synchronized (sStartPushLock) {
|
|
815
|
+
sStartPushData = pushData;
|
|
816
|
+
if (sAppReady.get() && sInstance != null) {
|
|
817
|
+
sInstance.doOnPushOpened(pushData);
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
} catch (Exception e) {
|
|
821
|
+
// React Native is highly unstable
|
|
822
|
+
PWLog.exception(e);
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
|
|
826
|
+
static void messageReceived(String pushData) {
|
|
827
|
+
try {
|
|
828
|
+
synchronized (sStartPushLock) {
|
|
829
|
+
sReceivedPushData = pushData;
|
|
830
|
+
if (sAppReady.get() && sInstance != null) {
|
|
831
|
+
sInstance.doOnPushReceived(pushData);
|
|
832
|
+
}
|
|
833
|
+
}
|
|
834
|
+
} catch (Exception e) {
|
|
835
|
+
// React Native is highly unstable
|
|
836
|
+
PWLog.exception(e);
|
|
837
|
+
}
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
|
|
841
|
+
public class JavascriptInterfaceCordova {
|
|
842
|
+
@JavascriptInterface
|
|
843
|
+
public void callFunction(String functionName) {
|
|
844
|
+
String url = String.format("%s();", functionName);
|
|
845
|
+
evalJs(url);
|
|
846
|
+
}
|
|
847
|
+
|
|
848
|
+
@JavascriptInterface
|
|
849
|
+
public void callFunction(String functionName, String args) {
|
|
850
|
+
String url;
|
|
851
|
+
if (args == null || args.isEmpty()) {
|
|
852
|
+
url = String.format("%s();", functionName);
|
|
853
|
+
} else {
|
|
854
|
+
url = String.format("%s(%s);", functionName, args);
|
|
855
|
+
}
|
|
856
|
+
evalJs(url);
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
|
|
860
|
+
@CordovaMethod
|
|
861
|
+
private boolean addJavaScriptInterface(JSONArray data, final CallbackContext callbackContext) {
|
|
862
|
+
try {
|
|
863
|
+
String name = data.getString(0);
|
|
864
|
+
PushwooshInApp.getInstance().addJavascriptInterface(new JavascriptInterfaceCordova(), name);
|
|
865
|
+
} catch (JSONException e) {
|
|
866
|
+
PWLog.error(TAG, "No parameters has been passed to addJavaScriptInterface function. Did you follow the guide correctly?", e);
|
|
867
|
+
return false;
|
|
868
|
+
}
|
|
869
|
+
|
|
870
|
+
return true;
|
|
871
|
+
}
|
|
872
|
+
|
|
895
873
|
}
|