cordova-plugin-mserviceinterface-2.0 1.0.43 → 1.0.45

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-mserviceinterface-2.0",
3
- "version": "1.0.43",
3
+ "version": "1.0.45",
4
4
  "description": "This plugin establishes the connection to the native interface and performs the requested task.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova-plugin-mserviceinterface-2.0"
5
- version="1.0.43">
5
+ version="1.0.45">
6
6
  <name>mserviceinterface-2.0</name>
7
7
  <description>This plugin establishes the connection to the native interface and performs the requested task.</description>
8
8
  <author>selfservit@gmail.com</author>
@@ -50,14 +50,8 @@
50
50
  </config-file>
51
51
  <config-file target="AndroidManifest.xml" parent="/manifest/application">
52
52
  <service android:name="com.selfservit.util.mInterfaceService" android:foregroundServiceType="location" android:enabled="true" android:exported="true"/>
53
- <service
54
- android:name="com.selfservit.util.backgroundNotification"
55
- android:permission="android.permission.BIND_JOB_SERVICE"
56
- android:exported="false">
57
- <intent-filter>
58
- <action android:name="com.onesignal.NotificationExtender" />
59
- </intent-filter>
60
- </service>
53
+ <meta-data android:name="com.onesignal.NotificationServiceExtension"
54
+ android:value="com.selfservit.util.backgroundNotification" />
61
55
  <receiver android:name="com.selfservit.util.mInterfaceReceiver" android:enabled="true" android:exported="true">
62
56
  <intent-filter>
63
57
  <action android:name="android.intent.action.BOOT_COMPLETED"/>
@@ -1,11 +1,13 @@
1
1
  package com.selfservit.util;
2
2
 
3
+ import android.content.Context;
3
4
  import android.os.Build;
4
5
  import android.os.Environment;
5
6
  import android.util.Log;
6
- import com.onesignal.NotificationExtenderService;
7
- import com.onesignal.OSNotificationDisplayedResult;
8
- import com.onesignal.OSNotificationReceivedResult;
7
+ import com.onesignal.OSNotification;
8
+ import com.onesignal.OSNotificationReceivedEvent;
9
+ import com.onesignal.OneSignal;
10
+
9
11
  import org.json.JSONException;
10
12
  import org.json.JSONObject;
11
13
  import java.io.BufferedReader;
@@ -22,90 +24,82 @@ import static com.selfservit.util.mInterfaceUtil.decrypt;
22
24
  import androidx.annotation.RequiresApi;
23
25
  import androidx.core.app.NotificationCompat;
24
26
 
25
- public class backgroundNotification extends NotificationExtenderService {
27
+ public class backgroundNotification implements OneSignal.OSRemoteNotificationReceivedHandler {
28
+
26
29
 
27
30
  String[] baseDirectory;
28
31
  File notificationsFile,fileDirectory;
29
32
  JSONObject msgBody, msgHeader;
30
33
  public static final Locale locale = Locale.US;
31
34
 
32
- @RequiresApi(api = Build.VERSION_CODES.O)
33
- @Override
34
- protected boolean onNotificationProcessing(OSNotificationReceivedResult notification) {
35
35
 
36
- OverrideSettings overrideSettings = new OverrideSettings();
37
- overrideSettings.extender = new NotificationCompat.Extender() {
38
- @Override
39
- public NotificationCompat.Builder extend(NotificationCompat.Builder builder) {
40
- // Sets the background notification color to White on Android 5.0+ devices.
41
- return builder.setColor(new BigInteger("#FFFFFF", 16).intValue());
42
- }
43
- };
36
+ @Override
37
+ public void remoteNotificationReceived(Context context, OSNotificationReceivedEvent osNotificationReceivedEvent) {
38
+ /* Do something with notification payload */
39
+ OSNotification notification = osNotificationReceivedEvent.getNotification();
40
+ try {
41
+ msgHeader = (JSONObject) notification.getAdditionalData().get("msgHeader");
42
+ String packageName = msgHeader.getString("appID");
43
+ baseDirectory = packageName.split("\\.");
44
+ String clientID = msgHeader.getString("clientID");
45
+ String countryCode = msgHeader.getString("countryCode");
46
+ msgBody = (JSONObject) notification.getAdditionalData().get("msgBody");
47
+ msgBody.put("notificationID",notification.getNotificationId());
48
+ String scrID = msgBody.getString("scrID");
49
+ String key = msgBody.getString("key");
50
+ String subKey = msgBody.getString("subKey");
51
+
52
+ if(scrID.contains("_chat")) {
53
+ if (!subKey.equals("")) {
54
+ fileDirectory = new File(mInterfaceUtil.rootDirectory + "/" + baseDirectory[(baseDirectory.length - 1)] + "/" + clientID + "/" + countryCode + "/" + "content_store" + "/" + "msvMsg" + "/" + "history"+ "/" + packageName + "/" + key + "/" + subKey);
55
+ if (!fileDirectory.exists()) {
56
+ fileDirectory.mkdirs();
57
+ }
58
+ notificationsFile = new File(fileDirectory, subKey + ".txt");
44
59
 
45
- /* Do something with notification payload */
46
- try {
47
- msgHeader = (JSONObject) notification.payload.additionalData.get("msgHeader");
48
- String packageName = msgHeader.getString("appID");
49
- baseDirectory = packageName.split("\\.");
50
- String clientID = msgHeader.getString("clientID");
51
- String countryCode = msgHeader.getString("countryCode");
52
- msgBody = (JSONObject) notification.payload.additionalData.get("msgBody");
53
- msgBody.put("notificationID",notification.payload.notificationID);
54
- String scrID = msgBody.getString("scrID");
55
- String key = msgBody.getString("key");
56
- String subKey = msgBody.getString("subKey");
57
-
58
- if(scrID.contains("_chat")) {
59
- if (!subKey.equals("")) {
60
- fileDirectory = new File(mInterfaceUtil.rootDirectory + "/" + baseDirectory[(baseDirectory.length - 1)] + "/" + clientID + "/" + countryCode + "/" + "content_store" + "/" + "msvMsg" + "/" + "history"+ "/" + packageName + "/" + key + "/" + subKey);
61
- if (!fileDirectory.exists()) {
62
- fileDirectory.mkdirs();
63
- }
64
- notificationsFile = new File(fileDirectory, subKey + ".txt");
65
-
66
60
 
67
- // Check if the specified file Exists or not
68
- if (notificationsFile.exists()) {
69
- System.out.println("Exists");
70
- try {
71
- FileReader fr = new FileReader(notificationsFile);
72
- BufferedReader bufferedReader = new BufferedReader(fr);
73
- StringBuilder notificationDatas = new StringBuilder();
74
- String line;
75
- while ((line = bufferedReader.readLine()) != null) {
76
- notificationDatas.append(line);
77
- System.out.println(line);
61
+ // Check if the specified file Exists or not
62
+ if (notificationsFile.exists()) {
63
+ System.out.println("Exists");
64
+ try {
65
+ FileReader fr = new FileReader(notificationsFile);
66
+ BufferedReader bufferedReader = new BufferedReader(fr);
67
+ StringBuilder notificationDatas = new StringBuilder();
68
+ String line;
69
+ while ((line = bufferedReader.readLine()) != null) {
70
+ notificationDatas.append(line);
71
+ System.out.println(line);
72
+ }
73
+ String notificationStr = decrypt(notificationDatas.toString());
74
+ notificationStr = notificationStr + "," +msgBody.toString() ;
75
+ FileWriter fw = new FileWriter(notificationsFile);
76
+ fw.write(mInterfaceUtil.encrypt(notificationStr));
77
+ fw.close();
78
+ } catch (Exception e) {
79
+ System.out.println(e);
80
+ }
81
+ } else {
82
+ System.out.println("Does not Exists");
83
+ try {
84
+ FileWriter fw = new FileWriter(notificationsFile);
85
+ fw.write(mInterfaceUtil.encrypt(","+ notification.getAdditionalData().getString("msgBody")));
86
+ fw.close();
87
+ } catch (IOException e1) {
88
+ e1.printStackTrace();
89
+ } catch (JSONException e) {
90
+ e.printStackTrace();
91
+ }
78
92
  }
79
- String notificationStr = decrypt(notificationDatas.toString());
80
- notificationStr = notificationStr + "," +msgBody.toString() ;
81
- FileWriter fw = new FileWriter(notificationsFile);
82
- fw.write(mInterfaceUtil.encrypt(notificationStr));
83
- fw.close();
84
- } catch (Exception e) {
85
- System.out.println(e);
86
- }
87
- } else {
88
- System.out.println("Does not Exists");
89
- try {
90
- FileWriter fw = new FileWriter(notificationsFile);
91
- fw.write(mInterfaceUtil.encrypt(","+ notification.payload.additionalData.getString("msgBody")));
92
- fw.close();
93
- } catch (IOException e1) {
94
- e1.printStackTrace();
95
- } catch (JSONException e) {
96
- e.printStackTrace();
97
93
  }
98
- }
99
- }
100
94
  } else {
101
95
  fileDirectory = new File(mInterfaceUtil.rootDirectory + "/" + baseDirectory[(baseDirectory.length - 1)] + "/" + clientID + "/" + countryCode + "/" + "notifications" + "/" + "unread");
102
96
  if (!fileDirectory.exists()) {
103
97
  fileDirectory.mkdirs();
104
98
  }
105
- notificationsFile = new File(fileDirectory, notification.payload.notificationID + ".json");
99
+ notificationsFile = new File(fileDirectory, notification.getNotificationId() + ".json");
106
100
  Date date = new Date();
107
101
  msgBody.put("dateTime",Date.parse(date.toString()));
108
- JSONObject jsonObj = notification.payload.toJSONObject();
102
+ JSONObject jsonObj = notification.toJSONObject();
109
103
  jsonObj.remove("rawPayload");
110
104
  FileWriter fw = new FileWriter(notificationsFile);
111
105
  fw.write(mInterfaceUtil.encrypt(jsonObj.toString()));
@@ -114,9 +108,11 @@ public class backgroundNotification extends NotificationExtenderService {
114
108
  } catch (JSONException | IOException e) {
115
109
  e.printStackTrace();
116
110
  }
117
- OSNotificationDisplayedResult displayedResult;
118
- displayedResult = displayNotification(overrideSettings);
119
- Log.d("OneSignalExample", "Notification displayed with id: " + displayedResult.androidNotificationId);
120
- return false;
121
- }
111
+ JSONObject data = notification.getAdditionalData();
112
+ Log.i("OneSignalExample", "Received Notification Data: " + data);
113
+
114
+ // If complete isn't call within a time period of 25 seconds, OneSignal internal logic will show the original notification
115
+ // To omit displaying a notification, pass `null` to complete()
116
+ osNotificationReceivedEvent.complete(notification);
117
+ }
122
118
  }
@@ -60,6 +60,8 @@ import com.google.android.gms.location.LocationSettingsStatusCodes;
60
60
  import com.google.android.gms.tasks.Task;
61
61
  import com.google.zxing.integration.android.IntentIntegrator;
62
62
  import com.google.zxing.integration.android.IntentResult;
63
+ import com.onesignal.OSDeviceState;
64
+ import com.onesignal.OneSignal;
63
65
 
64
66
  import org.apache.cordova.CallbackContext;
65
67
  import org.apache.cordova.CordovaInterface;
@@ -105,7 +107,10 @@ import id.zelory.compressor.Compressor;
105
107
 
106
108
  import static android.app.Activity.RESULT_OK;
107
109
 
110
+ import androidx.annotation.NonNull;
111
+ import androidx.annotation.Nullable;
108
112
  import androidx.annotation.RequiresApi;
113
+ import androidx.core.app.ActivityCompat;
109
114
 
110
115
  public class mInterface extends CordovaPlugin implements com.google.android.gms.location.LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, ResultCallback<LocationSettingsResult> {
111
116
  private static final String TAG = "mInterface";
@@ -201,6 +206,20 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
201
206
  System.out.println("Exception is: " + e.getMessage());
202
207
  callbackContext.error(e.getMessage());
203
208
  }
209
+ }else if (action.equals("GetFCMUtils")) {
210
+ try {
211
+ OSDeviceState device = OneSignal.getDeviceState();
212
+ String userId = device.getUserId();
213
+ //Get device's push token identifier
214
+ String pushToken = device.getPushToken();
215
+ JSONObject progressObj = new JSONObject();
216
+ progressObj.put("userId", userId);
217
+ progressObj.put("pushToken", pushToken);
218
+ callbackContext.success(progressObj);
219
+ } catch (Exception e) {
220
+ System.out.println("Exception is: " + e.getMessage());
221
+ callbackContext.error(e.getMessage());
222
+ }
204
223
  } else if (action.equals("GetSyncIndicator")) {
205
224
  try {
206
225
  File newQueueFolder, oldQueueFolder;