cordova-plugin-mserviceinterface-2.0 1.0.50 → 1.0.52
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 +1 -1
- package/plugin.xml +3 -3
- package/src/android/backgroundNotification.java +14 -14
- package/src/android/mInterface.java +305 -282
- package/src/android/mInterfaceService.java +68 -140
- package/src/android/mInterfaceUtil.java +116 -118
- package/src/ios/mInterface.m +3 -1
|
@@ -5,44 +5,39 @@ import static com.selfservit.util.mInterfaceUtil.decrypt;
|
|
|
5
5
|
import android.Manifest;
|
|
6
6
|
import android.annotation.TargetApi;
|
|
7
7
|
import android.app.AlarmManager;
|
|
8
|
-
import android.app.Notification;
|
|
9
|
-
import android.app.NotificationChannel;
|
|
10
|
-
import android.app.NotificationManager;
|
|
11
8
|
import android.app.PendingIntent;
|
|
12
9
|
import android.app.Service;
|
|
13
10
|
import android.content.Context;
|
|
14
11
|
import android.content.Intent;
|
|
15
12
|
import android.content.pm.PackageManager;
|
|
16
|
-
import android.graphics.Color;
|
|
17
13
|
import android.location.Location;
|
|
18
|
-
import android.media.RingtoneManager;
|
|
19
14
|
import android.net.ConnectivityManager;
|
|
20
15
|
import android.net.NetworkInfo;
|
|
21
|
-
import android.net.Uri;
|
|
22
16
|
import android.os.AsyncTask;
|
|
23
17
|
import android.os.Build;
|
|
24
18
|
import android.os.Bundle;
|
|
19
|
+
import android.os.Handler;
|
|
25
20
|
import android.os.IBinder;
|
|
26
21
|
import android.os.Looper;
|
|
27
22
|
import android.os.SystemClock;
|
|
23
|
+
import android.widget.Toast;
|
|
28
24
|
|
|
29
25
|
import androidx.annotation.NonNull;
|
|
30
26
|
import androidx.annotation.Nullable;
|
|
31
27
|
import androidx.annotation.RequiresApi;
|
|
32
|
-
import androidx.core.app.NotificationCompat;
|
|
33
28
|
|
|
34
29
|
import com.google.android.gms.common.ConnectionResult;
|
|
35
|
-
import com.google.android.gms.common.
|
|
30
|
+
import com.google.android.gms.common.GoogleApiAvailability;
|
|
36
31
|
import com.google.android.gms.common.api.GoogleApiClient;
|
|
37
32
|
import com.google.android.gms.common.api.PendingResult;
|
|
38
33
|
import com.google.android.gms.common.api.Status;
|
|
39
34
|
import com.google.android.gms.location.LocationRequest;
|
|
40
35
|
import com.google.android.gms.location.LocationServices;
|
|
36
|
+
import com.google.android.gms.location.Priority;
|
|
41
37
|
|
|
42
38
|
import org.json.JSONArray;
|
|
43
39
|
import org.json.JSONException;
|
|
44
40
|
import org.json.JSONObject;
|
|
45
|
-
import org.w3c.dom.Document;
|
|
46
41
|
|
|
47
42
|
import java.io.BufferedReader;
|
|
48
43
|
import java.io.BufferedWriter;
|
|
@@ -60,14 +55,11 @@ import java.util.Date;
|
|
|
60
55
|
import java.util.Timer;
|
|
61
56
|
import java.util.TimerTask;
|
|
62
57
|
|
|
63
|
-
import javax.xml.parsers.DocumentBuilder;
|
|
64
|
-
import javax.xml.parsers.DocumentBuilderFactory;
|
|
65
|
-
|
|
66
58
|
@TargetApi(Build.VERSION_CODES.O)
|
|
67
59
|
public class mInterfaceService extends Service implements com.google.android.gms.location.LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener {
|
|
68
60
|
public Timer setQueueInterval,
|
|
69
61
|
setQueueToServerInterval,
|
|
70
|
-
|
|
62
|
+
setTimerInterval,
|
|
71
63
|
setLocationTimeInterval;
|
|
72
64
|
GoogleApiClient mGoogleApiClient;
|
|
73
65
|
LocationRequest mLocationRequest;
|
|
@@ -78,67 +70,23 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
78
70
|
private static Timer setProcessInterval;
|
|
79
71
|
private static Context context;
|
|
80
72
|
public static boolean appStateTimerStatus = false;
|
|
81
|
-
String notification_icon, notification_color, app_name;
|
|
82
|
-
int imageResource, app_name_id, notification_color_id;
|
|
83
73
|
String locationUpdateInd = "false";
|
|
84
74
|
|
|
75
|
+
TimerTask setQueueIntervalObj;
|
|
76
|
+
|
|
85
77
|
@Override
|
|
86
78
|
public IBinder onBind(Intent intent) {
|
|
87
|
-
|
|
88
|
-
throw new UnsupportedOperationException("Not yet implemented");
|
|
79
|
+
return null;
|
|
89
80
|
}
|
|
90
81
|
|
|
91
82
|
@Override
|
|
92
83
|
@TargetApi(Build.VERSION_CODES.O)
|
|
93
84
|
public int onStartCommand(Intent intent, int flags, int startId) {
|
|
94
85
|
try {
|
|
95
|
-
|
|
86
|
+
context = getApplicationContext();
|
|
96
87
|
if (mInterfaceUtil.packageName.equals("")) {
|
|
97
88
|
mInterfaceUtil.packageName = getApplicationContext().getPackageName().split("\\.")[2];
|
|
98
89
|
}
|
|
99
|
-
notification_icon = "@drawable/ic_notification";
|
|
100
|
-
notification_color = "@color/notification_accent";
|
|
101
|
-
app_name = "@string/app_name";
|
|
102
|
-
imageResource = getResources().getIdentifier(notification_icon, null, getPackageName());
|
|
103
|
-
app_name_id = getResources().getIdentifier(app_name, null, getPackageName());
|
|
104
|
-
notification_color_id = getResources().getIdentifier(notification_color, null, getPackageName());
|
|
105
|
-
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
106
|
-
String NOTIFICATION_CHANNEL_ID = "com.selfservit.msdoubleointeg";
|
|
107
|
-
String channelName = "DoubleO Background Service";
|
|
108
|
-
NotificationChannel chan = new NotificationChannel(NOTIFICATION_CHANNEL_ID, channelName, NotificationManager.IMPORTANCE_NONE);
|
|
109
|
-
chan.setLightColor(Color.BLUE);
|
|
110
|
-
chan.setLockscreenVisibility(Notification.VISIBILITY_PRIVATE);
|
|
111
|
-
NotificationManager manager = (NotificationManager) getSystemService(this.NOTIFICATION_SERVICE);
|
|
112
|
-
assert manager != null;
|
|
113
|
-
manager.createNotificationChannel(chan);
|
|
114
|
-
|
|
115
|
-
Uri uri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
|
|
116
|
-
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(this);
|
|
117
|
-
Notification notification = notificationBuilder.setOngoing(true)
|
|
118
|
-
.setContentTitle(getResources().getString(app_name_id) + " is running")
|
|
119
|
-
.setSmallIcon(imageResource)
|
|
120
|
-
.setColor(getResources().getColor(notification_color_id))
|
|
121
|
-
.setPriority(NotificationManager.IMPORTANCE_MIN)
|
|
122
|
-
.setCategory(Notification.CATEGORY_SERVICE)
|
|
123
|
-
.setChannelId(NOTIFICATION_CHANNEL_ID)
|
|
124
|
-
.setVibrate(new long[]{1000, 1000, 1000, 1000, 1000})
|
|
125
|
-
.setSound(uri)
|
|
126
|
-
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
|
127
|
-
.build();
|
|
128
|
-
startForeground(2, notification);
|
|
129
|
-
} else {
|
|
130
|
-
Notification notification = new NotificationCompat.Builder(this)
|
|
131
|
-
.setContentTitle(getResources().getString(app_name_id) + " is running")
|
|
132
|
-
.setSmallIcon(imageResource)
|
|
133
|
-
.setColor(getResources().getColor(notification_color_id))
|
|
134
|
-
.setVisibility(NotificationCompat.VISIBILITY_PRIVATE)
|
|
135
|
-
.setCategory(Notification.CATEGORY_SERVICE)
|
|
136
|
-
.setOngoing(true)
|
|
137
|
-
.build();
|
|
138
|
-
|
|
139
|
-
startForeground(1, notification);
|
|
140
|
-
}
|
|
141
|
-
TimerTask setQueueIntervalObj, setTimerIntervelObj;
|
|
142
90
|
Intent serviceIntent = new Intent(getApplicationContext(), mInterfaceReceiver.class);
|
|
143
91
|
serviceIntent.setAction("com.example.checkservice");
|
|
144
92
|
final PendingIntent pIntent;
|
|
@@ -147,9 +95,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
147
95
|
0,
|
|
148
96
|
serviceIntent,
|
|
149
97
|
PendingIntent.FLAG_IMMUTABLE);
|
|
150
|
-
}
|
|
151
|
-
else
|
|
152
|
-
{
|
|
98
|
+
} else {
|
|
153
99
|
pIntent = PendingIntent.getBroadcast(getApplicationContext(),
|
|
154
100
|
0,
|
|
155
101
|
serviceIntent,
|
|
@@ -164,7 +110,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
164
110
|
setQueueIntervalObj = new TimerTask() {
|
|
165
111
|
public void run() {
|
|
166
112
|
if (isConnected()) {
|
|
167
|
-
new
|
|
113
|
+
new DispatchQueueMoveToServer().execute();
|
|
168
114
|
}
|
|
169
115
|
}
|
|
170
116
|
};
|
|
@@ -173,10 +119,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
173
119
|
// App State Info Process //
|
|
174
120
|
mInterfaceUtil.validateAppStateInfo(getApplicationContext());
|
|
175
121
|
if (!isGooglePlayServicesAvailable()) {
|
|
176
|
-
//need to write location log file...
|
|
177
122
|
System.out.println("Play services not available..");
|
|
178
123
|
}
|
|
179
|
-
|
|
180
124
|
String currentLine;
|
|
181
125
|
StringBuilder locConfigObj = new StringBuilder();
|
|
182
126
|
File baseDirectory = mInterfaceUtil.rootDirectory;
|
|
@@ -213,7 +157,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
213
157
|
if (setLocationTimeInterval == null) {
|
|
214
158
|
setLocationTimeInterval = new Timer();
|
|
215
159
|
setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L));
|
|
216
|
-
MINIMUM_INTERVAL = Long.parseLong(serverDateObj.optString("location_fetch_interval_in_seconds")
|
|
160
|
+
MINIMUM_INTERVAL = Long.parseLong(serverDateObj.optString("location_fetch_interval_in_seconds"));
|
|
217
161
|
createLocationRequest();
|
|
218
162
|
this.mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
219
163
|
.addConnectionCallbacks(this)
|
|
@@ -221,7 +165,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
221
165
|
.addApi(LocationServices.API)
|
|
222
166
|
.build();
|
|
223
167
|
mGoogleApiClient.connect();
|
|
224
|
-
}
|
|
168
|
+
}
|
|
225
169
|
getPeriodicalLocationUpdates();
|
|
226
170
|
update();
|
|
227
171
|
}
|
|
@@ -243,6 +187,12 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
243
187
|
return START_STICKY;
|
|
244
188
|
}
|
|
245
189
|
|
|
190
|
+
|
|
191
|
+
private void showToast() {
|
|
192
|
+
Handler handler = new Handler(Looper.getMainLooper());
|
|
193
|
+
handler.post(() -> Toast.makeText(mInterfaceService.this, "Background service is running!", Toast.LENGTH_SHORT).show());
|
|
194
|
+
}
|
|
195
|
+
|
|
246
196
|
public static void handleAppStateTimer(String status) {
|
|
247
197
|
try {
|
|
248
198
|
if (status.equalsIgnoreCase("failure")) {
|
|
@@ -254,7 +204,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
254
204
|
mInterfaceUtil.validateAppStateInfo(context);
|
|
255
205
|
}
|
|
256
206
|
};
|
|
257
|
-
setProcessInterval.schedule(setProcessIntervalObj,
|
|
207
|
+
setProcessInterval.schedule(setProcessIntervalObj,
|
|
208
|
+
60000,
|
|
209
|
+
60000);
|
|
258
210
|
}
|
|
259
211
|
} else {
|
|
260
212
|
if (setProcessInterval != null) {
|
|
@@ -272,12 +224,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
272
224
|
}
|
|
273
225
|
|
|
274
226
|
private boolean isGooglePlayServicesAvailable() {
|
|
275
|
-
int resultCode =
|
|
276
|
-
|
|
277
|
-
return true;
|
|
278
|
-
} else {
|
|
279
|
-
return false;
|
|
280
|
-
}
|
|
227
|
+
int resultCode = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this);
|
|
228
|
+
return ConnectionResult.SUCCESS == resultCode;
|
|
281
229
|
}
|
|
282
230
|
|
|
283
231
|
public void createLocationRequest() {
|
|
@@ -285,29 +233,36 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
285
233
|
mLocationRequest = LocationRequest.create();
|
|
286
234
|
mLocationRequest.setInterval(MINIMUM_INTERVAL * 1000);
|
|
287
235
|
mLocationRequest.setFastestInterval(MINIMUM_INTERVAL * 1000);
|
|
288
|
-
mLocationRequest.setPriority(
|
|
236
|
+
mLocationRequest.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
|
|
289
237
|
} catch (Exception e) {
|
|
290
238
|
e.printStackTrace();
|
|
291
239
|
}
|
|
292
240
|
}
|
|
293
241
|
|
|
294
242
|
protected void startLocationUpdates() {
|
|
243
|
+
boolean isPermissionGranted;
|
|
295
244
|
try {
|
|
296
245
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
297
246
|
if (checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && checkSelfPermission(Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
298
|
-
|
|
247
|
+
isPermissionGranted = false;
|
|
248
|
+
}else{
|
|
249
|
+
isPermissionGranted = true;
|
|
299
250
|
}
|
|
251
|
+
}else{
|
|
252
|
+
isPermissionGranted = true;
|
|
253
|
+
}
|
|
254
|
+
if(isPermissionGranted){
|
|
255
|
+
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this, Looper.getMainLooper());
|
|
300
256
|
}
|
|
301
|
-
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this, Looper.getMainLooper());
|
|
302
257
|
} catch (Exception e) {
|
|
303
258
|
e.printStackTrace();
|
|
304
259
|
}
|
|
305
260
|
}
|
|
306
261
|
|
|
307
262
|
@Override
|
|
308
|
-
public void onLocationChanged(Location location) {
|
|
263
|
+
public void onLocationChanged(@NonNull Location location) {
|
|
309
264
|
try {
|
|
310
|
-
if (locationUpdateInd
|
|
265
|
+
if (locationUpdateInd.equals("true")) {
|
|
311
266
|
locationUpdateInd = "false";
|
|
312
267
|
mCurrentLocation = location;
|
|
313
268
|
mLastUpdateTime = DateFormat.getTimeInstance().format(new Date());
|
|
@@ -345,13 +300,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
345
300
|
}
|
|
346
301
|
readerObj.close();
|
|
347
302
|
lastKnownLocation = locationData.toString().split(",");
|
|
348
|
-
|
|
349
|
-
result = true;
|
|
350
|
-
} else {
|
|
351
|
-
result = false;
|
|
352
|
-
}
|
|
353
|
-
} else {
|
|
354
|
-
result = false;
|
|
303
|
+
result = lastKnownLocation[0].equals(lat) && lastKnownLocation[1].equals(lng);
|
|
355
304
|
}
|
|
356
305
|
} catch (Exception e) {
|
|
357
306
|
e.printStackTrace();
|
|
@@ -380,7 +329,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
380
329
|
|
|
381
330
|
}
|
|
382
331
|
|
|
383
|
-
private class
|
|
332
|
+
private class DispatchQueueMoveToServer extends AsyncTask<String,
|
|
384
333
|
Void,
|
|
385
334
|
String> {
|
|
386
335
|
@Override
|
|
@@ -404,13 +353,12 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
404
353
|
if (isConnected()) {
|
|
405
354
|
for (int index = 0; index < accountsList.length(); index++) {
|
|
406
355
|
currentAccount = accountsList.optJSONObject(index);
|
|
407
|
-
clientID = currentAccount.optString("client_id")
|
|
408
|
-
countryCode = currentAccount.optString("country_code")
|
|
409
|
-
userID = currentAccount.optString("user_id")
|
|
410
|
-
clientUrl = currentAccount.optString("client_url")
|
|
356
|
+
clientID = currentAccount.optString("client_id");
|
|
357
|
+
countryCode = currentAccount.optString("country_code");
|
|
358
|
+
userID = currentAccount.optString("user_id");
|
|
359
|
+
clientUrl = currentAccount.optString("client_url");
|
|
411
360
|
File baseDirectory = mInterfaceUtil.rootDirectory;
|
|
412
361
|
File databaseDir = new File(baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database");
|
|
413
|
-
File processFileDir = new File(mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/process/");
|
|
414
362
|
if (databaseDir.exists()) {
|
|
415
363
|
String attachmentsPath = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/attachments";
|
|
416
364
|
String queuesPath = baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/queue";
|
|
@@ -423,8 +371,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
423
371
|
break;
|
|
424
372
|
}
|
|
425
373
|
String[] fileName = attachmentsFiles[attachIndex].toString().split("/");
|
|
426
|
-
String attachURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1]
|
|
427
|
-
statusIndication = new mInterfaceUtil().sendFilesToServer(attachmentsFiles[attachIndex].toString(), fileName[fileName.length - 1]
|
|
374
|
+
String attachURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=attachments&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1];
|
|
375
|
+
statusIndication = new mInterfaceUtil().sendFilesToServer(attachmentsFiles[attachIndex].toString(), fileName[fileName.length - 1], attachURL);
|
|
428
376
|
if (statusIndication.equals("true")) {
|
|
429
377
|
break;
|
|
430
378
|
}
|
|
@@ -441,8 +389,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
441
389
|
break;
|
|
442
390
|
}
|
|
443
391
|
String[] fileName = queueFiles[queueIndex].toString().split("/");
|
|
444
|
-
String queueURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=queue&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1]
|
|
445
|
-
new mInterfaceUtil().sendFilesToServer(queueFiles[queueIndex].toString(), fileName[fileName.length - 1]
|
|
392
|
+
String queueURL = clientUrl + "/common/components/QueueManager/QueueUpload.aspx?file_path=queue&client_id=" + clientID + "&country_code=" + countryCode + "&user_id=" + userID + "&file_name=" + fileName[fileName.length - 1];
|
|
393
|
+
new mInterfaceUtil().sendFilesToServer(queueFiles[queueIndex].toString(), fileName[fileName.length - 1], queueURL);
|
|
446
394
|
}
|
|
447
395
|
}
|
|
448
396
|
}
|
|
@@ -470,7 +418,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
470
418
|
}
|
|
471
419
|
}
|
|
472
420
|
|
|
473
|
-
private void getPeriodicalLocationUpdates()
|
|
421
|
+
private void getPeriodicalLocationUpdates() {
|
|
474
422
|
try {
|
|
475
423
|
locationUpdateInd = "true";
|
|
476
424
|
mInterfaceUtil.timerInd = "running";
|
|
@@ -488,25 +436,19 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
488
436
|
String> {
|
|
489
437
|
@Override
|
|
490
438
|
protected String doInBackground(String... urls) {
|
|
491
|
-
String currentLine,
|
|
492
|
-
BufferedReader myAccountsFileReader
|
|
439
|
+
String currentLine, clientID, countryCode, clientUrl, deviceID;
|
|
440
|
+
BufferedReader myAccountsFileReader;
|
|
493
441
|
StringBuilder myAccountsFileBuilder;
|
|
494
442
|
JSONArray accountsList;
|
|
495
|
-
JSONObject currentAccount
|
|
496
|
-
StringBuilder locationData
|
|
497
|
-
userData;
|
|
443
|
+
JSONObject currentAccount;
|
|
444
|
+
StringBuilder locationData;
|
|
498
445
|
BufferedReader readerObj;
|
|
499
446
|
BufferedWriter writerObj;
|
|
500
447
|
String serverData,
|
|
501
|
-
|
|
502
|
-
DocumentBuilderFactory dbfObj;
|
|
503
|
-
DocumentBuilder dbObj;
|
|
504
|
-
Document docObj;
|
|
448
|
+
requestURL;
|
|
505
449
|
OutputStreamWriter oStreamObj;
|
|
506
|
-
JSONObject userObj;
|
|
507
450
|
HttpURLConnection urlConObj;
|
|
508
451
|
URL requestPath;
|
|
509
|
-
String str = "";
|
|
510
452
|
|
|
511
453
|
try {
|
|
512
454
|
File baseDirectory = mInterfaceUtil.rootDirectory;
|
|
@@ -528,21 +470,14 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
528
470
|
|
|
529
471
|
for (int index = 0; index < accountsList.length(); index++) {
|
|
530
472
|
currentAccount = accountsList.optJSONObject(index);
|
|
531
|
-
if (currentAccount.optString("location_update_ind").
|
|
532
|
-
sessionID = mInterfaceUtil.sessionID;
|
|
533
|
-
localeID = mInterfaceUtil.localeID;
|
|
473
|
+
if (currentAccount.optString("location_update_ind").equals("true")) {
|
|
534
474
|
clientID = mInterfaceUtil.clientID;
|
|
535
475
|
countryCode = mInterfaceUtil.countryCode;
|
|
536
|
-
userID = mInterfaceUtil.userID;
|
|
537
|
-
employeeID = mInterfaceUtil.employeeId;
|
|
538
|
-
cvsUrl = mInterfaceUtil.cvsUrl;
|
|
539
476
|
clientUrl = mInterfaceUtil.clientUrl;
|
|
540
477
|
deviceID = mInterfaceUtil.deviceID;
|
|
541
|
-
|
|
542
|
-
requesturl = clientUrl + "/common/components/GeoLocation/update_device_location_offline.aspx";
|
|
543
|
-
|
|
478
|
+
requestURL = clientUrl + "/common/components/GeoLocation/update_device_location_offline.aspx";
|
|
544
479
|
/* SEND LOCATION */
|
|
545
|
-
requestPath = new URL(
|
|
480
|
+
requestPath = new URL(requestURL);
|
|
546
481
|
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
547
482
|
urlConObj.setDoOutput(true);
|
|
548
483
|
urlConObj.setRequestMethod("POST");
|
|
@@ -553,7 +488,6 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
553
488
|
oStreamObj.flush();
|
|
554
489
|
oStreamObj.close();
|
|
555
490
|
int responseCode = urlConObj.getResponseCode();
|
|
556
|
-
|
|
557
491
|
urlConObj.disconnect();
|
|
558
492
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
559
493
|
/* CLEARING THE LOCATION POINTS */
|
|
@@ -579,8 +513,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
579
513
|
private class UpdateLocation extends AsyncTask<String,
|
|
580
514
|
Void,
|
|
581
515
|
String> {
|
|
582
|
-
private String objLat
|
|
583
|
-
|
|
516
|
+
private final String objLat;
|
|
517
|
+
private final String objLon;
|
|
584
518
|
|
|
585
519
|
public UpdateLocation(String lat, String lon) {
|
|
586
520
|
this.objLat = lat;
|
|
@@ -630,8 +564,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
630
564
|
if (setQueueInterval != null) {
|
|
631
565
|
setQueueInterval.cancel();
|
|
632
566
|
}
|
|
633
|
-
if (
|
|
634
|
-
|
|
567
|
+
if (setTimerInterval != null) {
|
|
568
|
+
setTimerInterval.cancel();
|
|
635
569
|
}
|
|
636
570
|
Intent restartService = new Intent(getApplicationContext(),
|
|
637
571
|
this.getClass());
|
|
@@ -641,9 +575,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
641
575
|
restartServicePI = PendingIntent.getService(
|
|
642
576
|
getApplicationContext(), 1, restartService,
|
|
643
577
|
PendingIntent.FLAG_IMMUTABLE);
|
|
644
|
-
}
|
|
645
|
-
else
|
|
646
|
-
{
|
|
578
|
+
} else {
|
|
647
579
|
restartServicePI = PendingIntent.getService(
|
|
648
580
|
getApplicationContext(), 1, restartService,
|
|
649
581
|
PendingIntent.FLAG_ONE_SHOT);
|
|
@@ -665,8 +597,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
665
597
|
setQueueInterval.cancel();
|
|
666
598
|
}
|
|
667
599
|
|
|
668
|
-
if (
|
|
669
|
-
|
|
600
|
+
if (setTimerInterval != null) {
|
|
601
|
+
setTimerInterval.cancel();
|
|
670
602
|
}
|
|
671
603
|
|
|
672
604
|
startService(new Intent(getApplicationContext(), mInterfaceService.class));
|
|
@@ -683,9 +615,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
683
615
|
if (setQueueInterval != null) {
|
|
684
616
|
setQueueInterval.cancel();
|
|
685
617
|
}
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
setTimerIntervel.cancel();
|
|
618
|
+
if (setTimerInterval != null) {
|
|
619
|
+
setTimerInterval.cancel();
|
|
689
620
|
}
|
|
690
621
|
startService(new Intent(getApplicationContext(), mInterfaceService.class));
|
|
691
622
|
} catch (Exception e) {
|
|
@@ -693,14 +624,11 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
693
624
|
}
|
|
694
625
|
}
|
|
695
626
|
|
|
627
|
+
|
|
696
628
|
public boolean isConnected() {
|
|
697
|
-
ConnectivityManager online = (ConnectivityManager) getSystemService(
|
|
629
|
+
ConnectivityManager online = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
|
|
698
630
|
NetworkInfo networkInfo = online.getActiveNetworkInfo();
|
|
699
|
-
|
|
700
|
-
return true;
|
|
701
|
-
} else {
|
|
702
|
-
return false;
|
|
703
|
-
}
|
|
631
|
+
return networkInfo != null && networkInfo.isConnected();
|
|
704
632
|
}
|
|
705
633
|
|
|
706
634
|
|
|
@@ -728,7 +656,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
728
656
|
JSONObject serverDateObj = new JSONObject(decrypt(locConfigObj.toString()));
|
|
729
657
|
setLocationTimeInterval.cancel();
|
|
730
658
|
setLocationTimeInterval = new Timer();
|
|
731
|
-
setLocationTimeInterval.schedule(timerTask,
|
|
659
|
+
setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(serverDateObj.optString("location_fetch_interval_in_seconds")) * 1000L));
|
|
732
660
|
}
|
|
733
661
|
}
|
|
734
662
|
|