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.
@@ -1,5 +1,7 @@
1
1
  package com.selfservit.util;
2
2
 
3
+ import static android.app.Activity.RESULT_OK;
4
+
3
5
  import android.Manifest;
4
6
  import android.app.Activity;
5
7
  import android.app.ActivityManager;
@@ -23,6 +25,7 @@ import android.graphics.Canvas;
23
25
  import android.graphics.Matrix;
24
26
  import android.graphics.Paint;
25
27
  import android.location.Location;
28
+ import androidx.exifinterface.media.ExifInterface;
26
29
  import android.media.MediaMetadataRetriever;
27
30
  import android.media.ThumbnailUtils;
28
31
  import android.net.ConnectivityManager;
@@ -32,7 +35,6 @@ import android.os.AsyncTask;
32
35
  import android.os.Build;
33
36
  import android.os.Bundle;
34
37
  import android.os.Environment;
35
- import android.os.FileUtils;
36
38
  import android.os.PowerManager;
37
39
  import android.provider.DocumentsContract;
38
40
  import android.provider.MediaStore;
@@ -45,7 +47,11 @@ import android.view.KeyEvent;
45
47
  import android.webkit.MimeTypeMap;
46
48
  import android.widget.ProgressBar;
47
49
  import android.widget.Toast;
48
- import android.media.ExifInterface;
50
+
51
+ import androidx.annotation.NonNull;
52
+ import androidx.annotation.Nullable;
53
+ import androidx.annotation.RequiresApi;
54
+ import androidx.core.app.ActivityCompat;
49
55
 
50
56
  import com.google.android.gms.common.ConnectionResult;
51
57
  import com.google.android.gms.common.api.GoogleApiClient;
@@ -57,17 +63,15 @@ import com.google.android.gms.location.LocationServices;
57
63
  import com.google.android.gms.location.LocationSettingsRequest;
58
64
  import com.google.android.gms.location.LocationSettingsResult;
59
65
  import com.google.android.gms.location.LocationSettingsStatusCodes;
60
- import com.google.android.gms.tasks.Task;
66
+ import com.google.android.gms.location.Priority;
61
67
  import com.google.zxing.integration.android.IntentIntegrator;
62
68
  import com.google.zxing.integration.android.IntentResult;
63
69
  import com.onesignal.OSDeviceState;
64
70
  import com.onesignal.OneSignal;
65
71
 
66
72
  import org.apache.cordova.CallbackContext;
67
- import org.apache.cordova.CordovaInterface;
68
73
  import org.apache.cordova.CordovaPlugin;
69
74
  import org.apache.cordova.CordovaResourceApi;
70
- import org.apache.cordova.CordovaWebView;
71
75
  import org.apache.cordova.PermissionHelper;
72
76
  import org.apache.cordova.PluginResult;
73
77
  import org.json.JSONArray;
@@ -94,24 +98,11 @@ import java.util.Date;
94
98
  import java.util.List;
95
99
  import java.util.Stack;
96
100
  import java.util.TimeZone;
97
- import java.util.regex.Matcher;
98
- import java.util.regex.Pattern;
99
101
  import java.util.zip.ZipEntry;
100
102
  import java.util.zip.ZipInputStream;
101
- import java.util.List;
102
- import java.util.ArrayList;
103
- import java.util.Arrays;
104
-
105
103
 
106
104
  import id.zelory.compressor.Compressor;
107
105
 
108
- import static android.app.Activity.RESULT_OK;
109
-
110
- import androidx.annotation.NonNull;
111
- import androidx.annotation.Nullable;
112
- import androidx.annotation.RequiresApi;
113
- import androidx.core.app.ActivityCompat;
114
-
115
106
  public class mInterface extends CordovaPlugin implements com.google.android.gms.location.LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, ResultCallback<LocationSettingsResult> {
116
107
  private static final String TAG = "mInterface";
117
108
  public Stack<ProgressDialog> spinnerDialogStack = new Stack<ProgressDialog>();
@@ -143,6 +134,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
143
134
  private static final long INTERVAL = 5 * 60 * 1000;
144
135
  private static final long FASTEST_INTERVAL = 5 * 60 * 1000;
145
136
  public static String attachmentDestPath = "";
137
+
146
138
  /* START SERVICE WHEN USER COMES FROM INACTIVE TO ACTIVE STATE IF SERVICE NOT RUNNING */
147
139
  @Override
148
140
  public void onResume(boolean multitasking) {
@@ -158,39 +150,37 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
158
150
  @RequiresApi(api = Build.VERSION_CODES.O)
159
151
  @Override
160
152
  public boolean execute(final String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
161
- mInterfaceUtil.rootDirectory = new File(cordova.getActivity().getExternalFilesDir(""), "");
153
+ callback = callbackContext;
154
+ mInterfaceUtil.rootDirectory = new File(cordova.getActivity().getExternalFilesDir(""), "");
162
155
  if (mInterfaceUtil.packageName.equals("")) {
163
156
  mInterfaceUtil.packageName = cordova.getActivity().getApplicationContext().getPackageName().split("\\.")[2];
164
157
  }
165
158
  /* START BACKGROUND SERVICE IF NOT RUNNING ALREADY */
166
159
  if (action.equals("StartService")) {
167
160
  boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
161
+ System.out.println("appInfoUpdated: " + appInfoUpdated);
168
162
  //if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
169
163
  if (!isServiceRunning(backgroundNotification.class)) {
170
164
  cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), backgroundNotification.class));
171
165
  }
172
166
  if (!isServiceRunning(mInterfaceService.class)) {
173
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
174
- cordova.getActivity().startForegroundService(new Intent(cordova.getActivity().getApplicationContext(), mInterfaceService.class));
175
- } else {
176
- cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), mInterfaceService.class));
177
- }
167
+ cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), mInterfaceService.class));
178
168
  } else {
179
169
  System.out.println("Service is already running");
180
170
  }
181
171
  callbackContext.success("Success");
182
- }else if (action.equals("showToastWithOptions")) {
172
+ } else if (action.equals("showToastWithOptions")) {
183
173
  try {
184
- if(args.getJSONObject(0).optString("duration").equals("long")){
185
- Toast.makeText(cordova.getActivity().getApplicationContext(),args.getJSONObject(0).optString("message"), Toast.LENGTH_LONG).show();
174
+ if (args.getJSONObject(0).optString("duration").equals("long")) {
175
+ Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_LONG).show();
186
176
  } else {
187
- Toast.makeText(cordova.getActivity().getApplicationContext(),args.getJSONObject(0).optString("message"), Toast.LENGTH_SHORT).show();
177
+ Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_SHORT).show();
188
178
  }
189
179
  } catch (Exception exception) {
190
180
  callbackContext.success("Show Toast having exception");
191
181
  }
192
182
  } else if (action.equals("CheckLocationAccuracy")) {
193
- int locationInt = 111;
183
+ int locationInt;
194
184
  try {
195
185
  locationInt = Settings.Secure.getInt(this.cordova.getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);
196
186
  callbackContext.success(Integer.toString(locationInt));
@@ -198,7 +188,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
198
188
  System.out.println("Exception is: " + e.getMessage());
199
189
  callbackContext.error(e.getMessage());
200
190
  }
201
- }else if (action.equals("GetBase64String")) {
191
+ } else if (action.equals("GetBase64String")) {
202
192
  try {
203
193
  String imageString = getBase64String(args.getJSONObject(0).optString("filePath"));
204
194
  callbackContext.success(imageString);
@@ -206,16 +196,20 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
206
196
  System.out.println("Exception is: " + e.getMessage());
207
197
  callbackContext.error(e.getMessage());
208
198
  }
209
- }else if (action.equals("GetFCMUtils")) {
199
+ } else if (action.equals("GetFCMUtils")) {
210
200
  try {
211
201
  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);
202
+ if (device != null) {
203
+ String userId = device.getUserId();
204
+ //Get device's push token identifier
205
+ String pushToken = device.getPushToken();
206
+ JSONObject progressObj = new JSONObject();
207
+ progressObj.put("userId", userId);
208
+ progressObj.put("pushToken", pushToken);
209
+ callbackContext.success(progressObj);
210
+ } else {
211
+ callbackContext.error("Error occurred");
212
+ }
219
213
  } catch (Exception e) {
220
214
  System.out.println("Exception is: " + e.getMessage());
221
215
  callbackContext.error(e.getMessage());
@@ -229,7 +223,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
229
223
  URL requestPath;
230
224
  HttpURLConnection urlConObj;
231
225
  OutputStreamWriter oStreamObj;
232
- String currentLinedata = "";
226
+ String currentLinedata;
233
227
  String client_id = args.getJSONObject(0).optString("client_id");
234
228
  String country_code = args.getJSONObject(0).optString("country_code");
235
229
  String user_id = args.getJSONObject(0).optString("user_id");
@@ -239,23 +233,23 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
239
233
  try {
240
234
  oldQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue");
241
235
  newQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + client_id + "/" + country_code + "/database/queue");
242
- if(oldQueueFolder.exists()) {
243
- if(oldQueueFolder.listFiles().length == 0){
236
+ if (oldQueueFolder.exists()) {
237
+ if (oldQueueFolder.listFiles().length == 0) {
244
238
  syncIndication = true;
245
239
  }
246
- } else{
240
+ } else {
247
241
  syncIndication = true;
248
242
  }
249
- if(syncIndication) {
250
- if(newQueueFolder.exists()){
251
- if(newQueueFolder.listFiles().length != 0){
243
+ if (syncIndication) {
244
+ if (newQueueFolder.exists()) {
245
+ if (newQueueFolder.listFiles().length != 0) {
252
246
  syncIndication = false;
253
247
  }
254
248
  }
255
249
  }
256
- if(syncIndication) {
250
+ if (syncIndication) {
257
251
  requestPath = new URL(requestUrl);
258
- urlConObj = (HttpURLConnection)requestPath.openConnection();
252
+ urlConObj = (HttpURLConnection) requestPath.openConnection();
259
253
  urlConObj.setDoOutput(true);
260
254
  urlConObj.setRequestMethod("POST");
261
255
  urlConObj.setRequestProperty("CONTENT-TYPE", "application/text");
@@ -269,31 +263,26 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
269
263
  readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
270
264
  currentLine = readerObj.readLine();
271
265
  readerObj.close();
272
- currentLinedata = currentLine.toString();
266
+ currentLinedata = currentLine;
273
267
  urlConObj.disconnect();
274
- if(currentLinedata.equals("true")) {
275
- syncIndication = true;
276
- } else {
277
- syncIndication = false;
278
- }
268
+ syncIndication = currentLinedata.equals("true");
279
269
  }
280
270
  callbackContext.success(String.valueOf(syncIndication));
281
- }catch(Exception e) {
271
+ } catch (Exception e) {
282
272
  callbackContext.success(e.getMessage());
283
273
  }
284
274
  } catch (Exception e) {
285
275
  callbackContext.success(e.getMessage());
286
276
  }
287
- }
288
- else if (action.equals("TurnOnAutomaticDateTime")) {
277
+ } else if (action.equals("TurnOnAutomaticDateTime")) {
289
278
  Intent intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
290
279
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
291
280
  cordova.getActivity().getApplicationContext().startActivity(intent);
292
281
  callbackContext.success();
293
282
  } else if (action.equals("CheckAutomaticTime")) {
294
283
  boolean timeValue = isTimeAutomatic(cordova.getActivity().getApplicationContext());
295
- String valueString = "";
296
- if (timeValue == true) {
284
+ String valueString;
285
+ if (timeValue) {
297
286
  valueString = "true";
298
287
  } else {
299
288
  valueString = "false";
@@ -306,8 +295,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
306
295
  System.out.println("service check is: " + str + " " + isServiceRunning(mInterfaceService.class));
307
296
  }
308
297
  callbackContext.success(str);
309
- } else if (action.equals("EnableGPSService")) {
310
- EnableGPSAutoMatically(callbackContext);
311
298
  } else if (action.equals("GetPermissions")) {
312
299
  getPermissions(args, callbackContext);
313
300
  return true;
@@ -333,7 +320,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
333
320
  unzip(args, callbackContext);
334
321
  return true;
335
322
  } else if (action.equals("EnableGPSService")) {
336
- EnableGPSAutoMatically(callbackContext);
323
+ EnableGPSAutomatically(callbackContext);
337
324
  } else if ("GoHome".equals(action)) {
338
325
  try {
339
326
  Intent i = new Intent(Intent.ACTION_MAIN);
@@ -436,7 +423,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
436
423
  URL requestPath;
437
424
  HttpURLConnection urlConObj;
438
425
  OutputStreamWriter oStreamObj;
439
- String currentLinedata = "";
426
+ String currentLinedata;
440
427
  String client_id = args.getJSONObject(0).optString("client_id");
441
428
  String country_code = args.getJSONObject(0).optString("country_code");
442
429
  String user_id = args.getJSONObject(0).optString("user_id");
@@ -475,13 +462,9 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
475
462
  readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
476
463
  currentLine = readerObj.readLine();
477
464
  readerObj.close();
478
- currentLinedata = currentLine.toString();
465
+ currentLinedata = currentLine;
479
466
  urlConObj.disconnect();
480
- if (currentLinedata.equals("true")) {
481
- syncIndication = true;
482
- } else {
483
- syncIndication = false;
484
- }
467
+ syncIndication = currentLinedata.equals("true");
485
468
  }
486
469
  callbackContext.success(String.valueOf(syncIndication));
487
470
  } catch (Exception e) {
@@ -490,28 +473,25 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
490
473
  } catch (Exception e) {
491
474
  callbackContext.success(e.getMessage());
492
475
  }
493
- }
494
- else if (action.equals("FileChooser")) {
476
+ } else if (action.equals("FileChooser")) {
495
477
  attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
496
478
  chooseFile(callbackContext);
497
479
  return true;
498
480
  } else if (action.equals("GetThumbnail")) {
499
- String filePath = mInterfaceUtil.rootDirectory + "/" +args.optJSONObject(0).optString("filePath");
500
- String thumbnail= getFileThumbnail(filePath, args.optJSONObject(0).optString("fileExtension"));
501
- callback.success(thumbnail);
502
- return true;
503
- }
504
- else if (action.equals("DownloadChatAttachFile")) {
481
+ String filePath = mInterfaceUtil.rootDirectory + "/" + args.optJSONObject(0).optString("filePath");
482
+ String thumbnail = getFileThumbnail(filePath, args.optJSONObject(0).optString("fileExtension"));
483
+ callback.success(thumbnail);
484
+ return true;
485
+ } else if (action.equals("DownloadChatAttachFile")) {
505
486
  String url = args.optJSONObject(0).optString("url"),
506
487
  filePath = args.optJSONObject(0).optString("filePath"),
507
488
  thumbnailInd = args.optJSONObject(0).optString("thumbnailInd");
508
489
  PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
509
490
  pluginResult.setKeepCallback(true);
510
491
  callbackContext.sendPluginResult(pluginResult);
511
- new mInterfaceUtil().DownloadChatAttachment(url,filePath, thumbnailInd, cordova.getActivity().getApplicationContext(),callbackContext, cordova.getActivity());
492
+ new mInterfaceUtil().DownloadChatAttachment(url, filePath, thumbnailInd, cordova.getActivity().getApplicationContext(), callbackContext, cordova.getActivity());
512
493
  return true;
513
- }
514
- else if (action.equals("SendChatAttachment")) {
494
+ } else if (action.equals("SendChatAttachment")) {
515
495
  String filePath = args.optJSONObject(0).optString("filePath"),
516
496
  serverPath = args.optJSONObject(0).optString("serverPath"),
517
497
  fileName = args.optJSONObject(0).optString("fileName"),
@@ -519,10 +499,9 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
519
499
  PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
520
500
  pluginResult.setKeepCallback(true);
521
501
  callbackContext.sendPluginResult(pluginResult);
522
- new mInterfaceUtil().sendChatAttachment(filePath,fileName, attachURL, cordova.getActivity(),callbackContext);
502
+ new mInterfaceUtil().sendChatAttachment(filePath, fileName, attachURL, cordova.getActivity(), callbackContext);
523
503
  return true;
524
- }
525
- else if (action.equals("SendAttachmentToServer")) {
504
+ } else if (action.equals("SendAttachmentToServer")) {
526
505
  String statusIndication = "false";
527
506
  JSONObject inputFileObj;
528
507
  try {
@@ -547,8 +526,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
547
526
  callbackContext.error("failure");
548
527
  }
549
528
  return true;
550
- }
551
- else if (action.equals("ReadFile")) {
529
+ } else if (action.equals("ReadFile")) {
552
530
  try {
553
531
  new mInterfaceUtil().readFile(args, callbackContext);
554
532
  } catch (Exception e) {
@@ -587,7 +565,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
587
565
  } else if (action.equals("CopyFile")) {
588
566
  arguments = args;
589
567
  new mInterfaceUtil().copyFile(callbackContext, arguments);
590
- }else if (action.equals("CopyAttachmentFile")) {
568
+ } else if (action.equals("CopyAttachmentFile")) {
591
569
  arguments = args;
592
570
  new mInterfaceUtil().copyAttachmentFile(callbackContext, arguments);
593
571
  } else if (action.equals("CopyConfigFile")) {
@@ -598,9 +576,9 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
598
576
  } else if (action.equals("RefreshTimeProfile")) {
599
577
  JSONObject timeObj = args.getJSONObject(0);
600
578
  String date, hour, minute;
601
- date = timeObj.optString("serverDate").toString();
602
- hour = timeObj.optString("serverHour").toString();
603
- minute = timeObj.optString("serverMinute").toString();
579
+ date = timeObj.optString("serverDate");
580
+ hour = timeObj.optString("serverHour");
581
+ minute = timeObj.optString("serverMinute");
604
582
  String returnStatus = new mInterfaceUtil().refreshTimeProfile(date, hour, minute);
605
583
  if (returnStatus.equals("true")) {
606
584
  callbackContext.success("success");
@@ -614,9 +592,9 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
614
592
  AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_HOLO_DARK);
615
593
  AlertDialog alertDialog;
616
594
  versionObj = args.getJSONObject(0);
617
- appVersion = versionObj.optString("appVersion").toString();
618
- softwareProductVersion = versionObj.optString("softwareProductVersion").toString();
619
- softwareProductSubVersion = versionObj.optString("softwareProductSubVersion").toString();
595
+ appVersion = versionObj.optString("appVersion");
596
+ softwareProductVersion = versionObj.optString("softwareProductVersion");
597
+ softwareProductSubVersion = versionObj.optString("softwareProductSubVersion");
620
598
  builder.setTitle("New Update");
621
599
  builder.setMessage("Your mservice version is " + appVersion + ". There is an updated version " + softwareProductVersion + "." + softwareProductSubVersion + " available. Please update.");
622
600
  builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
@@ -655,9 +633,9 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
655
633
  AlertDialog alertDialog;
656
634
  AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_HOLO_DARK);
657
635
  versionObj = args.getJSONObject(0);
658
- appVersion = versionObj.optString("appVersion").toString();
659
- softwareProductVersion = versionObj.optString("softwareProductVersion").toString();
660
- softwareProductSubVersion = versionObj.optString("softwareProductSubVersion").toString();
636
+ appVersion = versionObj.optString("appVersion");
637
+ softwareProductVersion = versionObj.optString("softwareProductVersion");
638
+ softwareProductSubVersion = versionObj.optString("softwareProductSubVersion");
661
639
  builder.setTitle("New Update");
662
640
  builder.setMessage("Your mservice version is " + appVersion + ". Please upgrade the app to " + softwareProductVersion + "." + softwareProductSubVersion + " to proceed.");
663
641
  builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
@@ -691,7 +669,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
691
669
  try {
692
670
  Intent intent = new Intent(Intent.ACTION_VIEW);
693
671
  Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", imageFilePath);
694
- intent.setDataAndType(contentUri, getMimeType(filePath,null));
672
+ intent.setDataAndType(contentUri, getMimeType(filePath, null));
695
673
  intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
696
674
  cordova.getActivity().startActivity(intent);
697
675
  callbackContext.success();
@@ -700,7 +678,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
700
678
  }
701
679
  } else if (action.equals("CaptureImageFromCamera")) {
702
680
  try {
703
- if(args.length()>0){
681
+ if (args.length() > 0) {
704
682
  attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
705
683
  cameraAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
706
684
  }
@@ -711,7 +689,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
711
689
  }
712
690
  } else if (action.equals("PickImageFromGallery")) {
713
691
  try {
714
- if(args.length()>0) {
692
+ if (args.length() > 0) {
715
693
  attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
716
694
  galleryAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
717
695
  }
@@ -746,7 +724,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
746
724
  final DownloadTask downloadTask = new DownloadTask(cordova.getActivity());
747
725
  downloadTask.execute(args.optJSONObject(0).optString("url"), args.optJSONObject(0).optString("filePath"), args.optJSONObject(0).optString("thumbnailInd"));
748
726
  return true;
749
- }else if ("QueueProcessor".equals(action)) {
727
+ } else if ("QueueProcessor".equals(action)) {
750
728
  new mInterfaceUtil().queueProcessor(callbackContext);
751
729
  return true;
752
730
  } else if (action.equals("ScanQRCode")) {
@@ -787,43 +765,41 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
787
765
  callbackContext.error("failed to update app info");
788
766
  }
789
767
  return true;
790
- }
791
- else if (action.equals("MoveFile")) {
768
+ } else if (action.equals("MoveFile")) {
792
769
  arguments = args;
793
770
  new mInterfaceUtil().moveFile(callbackContext, arguments);
794
- }else if (action.equals("SendAttachment")) {
771
+ } else if (action.equals("SendAttachment")) {
795
772
 
796
773
  JSONObject appInfo = args.getJSONObject(0);
797
- mInterfaceUtil.app_id = appInfo.optString("app_id").toString();
798
- mInterfaceUtil.platform = appInfo.optString("platform").toString();
799
- mInterfaceUtil.deviceID = appInfo.optString("device_id").toString();
774
+ mInterfaceUtil.app_id = appInfo.optString("app_id");
775
+ mInterfaceUtil.platform = appInfo.optString("platform");
776
+ mInterfaceUtil.deviceID = appInfo.optString("device_id");
800
777
  new mInterfaceUtil().moveFile(callbackContext, arguments);
801
- }
802
- else if (action.equals("OpenSms")) {
778
+ } else if (action.equals("OpenSms")) {
803
779
  String contact_number, smsBody;
804
780
  Intent smsIntent;
805
781
  PluginResult result;
806
782
  try {
807
- contact_number = args.getJSONObject(0).optString("contact_number");
808
- if(contact_number != null ) {
809
- if(!contact_number.equals("") ) {
810
- if(validateMobileNumber(contact_number)){
783
+ contact_number = args.getJSONObject(0).optString("contact_number");
784
+ if (contact_number != null) {
785
+ if (!contact_number.equals("")) {
786
+ if (validateMobileNumber(contact_number)) {
811
787
  smsBody = args.getJSONObject(0).optString("msgBody");
812
788
  smsIntent = new Intent(Intent.ACTION_VIEW);
813
789
  smsIntent.putExtra("sms_body", smsBody);
814
790
  smsIntent.setData(Uri.parse("sms:" + contact_number));
815
791
  smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
816
792
  cordova.getActivity().getApplicationContext().startActivity(smsIntent);
817
- }else{
818
- result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_INVALID");
793
+ } else {
794
+ result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_INVALID");
819
795
  callback.sendPluginResult(result);
820
796
  }
821
- }else{
822
- result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
797
+ } else {
798
+ result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
823
799
  callback.sendPluginResult(result);
824
800
  }
825
- }else{
826
- result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
801
+ } else {
802
+ result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
827
803
  callback.sendPluginResult(result);
828
804
  }
829
805
  } catch (JSONException e) {
@@ -832,28 +808,28 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
832
808
  callback.sendPluginResult(result);
833
809
  }
834
810
  return true;
835
- }else if (action.equals("OpenDialPad")) {
811
+ } else if (action.equals("OpenDialPad")) {
836
812
  Intent intent;
837
- PluginResult result;
813
+ PluginResult result;
838
814
  try {
839
815
  String contact_number = args.getJSONObject(0).optString("contact_number");
840
- if(contact_number != null ) {
841
- if(!contact_number.equals("") ) {
842
- if(validateMobileNumber(contact_number)){
816
+ if (contact_number != null) {
817
+ if (!contact_number.equals("")) {
818
+ if (validateMobileNumber(contact_number)) {
843
819
 
844
820
  intent = new Intent(Intent.ACTION_DIAL);
845
821
  intent.setData(Uri.parse("tel:" + contact_number));
846
822
  intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
847
823
  cordova.getActivity().getApplicationContext().startActivity(intent);
848
- }else{
824
+ } else {
849
825
  result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_INVALID");
850
826
  callback.sendPluginResult(result);
851
827
  }
852
- }else{
828
+ } else {
853
829
  result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
854
830
  callback.sendPluginResult(result);
855
831
  }
856
- }else{
832
+ } else {
857
833
  result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
858
834
  callback.sendPluginResult(result);
859
835
  }
@@ -864,17 +840,17 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
864
840
  result = new PluginResult(PluginResult.Status.ERROR, exception.getMessage());
865
841
  callback.sendPluginResult(result);
866
842
  }
867
- }else if (action.equals("OpenEmail")) {
843
+ } else if (action.equals("OpenEmail")) {
868
844
  PluginResult result;
869
845
  String toEmail, ccEmail, subject, body, mailto;
870
- try{
871
- toEmail = args.getJSONObject(0).optString("toEmail");
872
- ccEmail = args.getJSONObject(0).optString("ccEmail");
873
- subject = args.getJSONObject(0).optString("subject");
874
- body = args.getJSONObject(0).optString("body");
875
- if(toEmail != null ) {
876
- if(!toEmail.equals("") ) {
877
- if(Patterns.EMAIL_ADDRESS.matcher(toEmail).matches()){
846
+ try {
847
+ toEmail = args.getJSONObject(0).optString("toEmail");
848
+ ccEmail = args.getJSONObject(0).optString("ccEmail");
849
+ subject = args.getJSONObject(0).optString("subject");
850
+ body = args.getJSONObject(0).optString("body");
851
+ if (toEmail != null) {
852
+ if (!toEmail.equals("")) {
853
+ if (Patterns.EMAIL_ADDRESS.matcher(toEmail).matches()) {
878
854
  mailto = "mailto:" + toEmail +
879
855
  "?cc=" + ccEmail +
880
856
  "&subject=" + Uri.encode(subject) +
@@ -883,16 +859,16 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
883
859
  emailIntent.setData(Uri.parse(mailto));
884
860
  emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
885
861
  cordova.getActivity().getApplicationContext().startActivity(emailIntent);
886
- }else{
862
+ } else {
887
863
  result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_INVALID");
888
864
  callback.sendPluginResult(result);
889
865
  }
890
- }else{
891
- result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_NOT_AVAILABLE");
866
+ } else {
867
+ result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_NOT_AVAILABLE");
892
868
  callback.sendPluginResult(result);
893
869
  }
894
- }else{
895
- result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_NOT_AVAILABLE");
870
+ } else {
871
+ result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_NOT_AVAILABLE");
896
872
  callback.sendPluginResult(result);
897
873
  }
898
874
  } catch (Exception e) {
@@ -901,6 +877,20 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
901
877
  callback.sendPluginResult(result);
902
878
  }
903
879
 
880
+ } else if (action.equals("OpenAppSettings")) {
881
+ PluginResult result;
882
+ try {
883
+ Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
884
+ Uri uri = Uri.fromParts("package", cordova.getActivity().getPackageName(), null);
885
+ intent.setData(uri);
886
+ cordova.getActivity().startActivity(intent);
887
+ callbackContext.success("success");
888
+ } catch (Exception e) {
889
+ e.printStackTrace();
890
+ result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
891
+ callback.sendPluginResult(result);
892
+ }
893
+
904
894
  }
905
895
  return true;
906
896
  }
@@ -909,8 +899,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
909
899
  String regex;
910
900
  boolean result = false;
911
901
  try {
912
- regex = "^\\+?\\d[\\d ]+$";
913
- if (mobileNo.matches(regex)) {
902
+ regex = "^\\+?\\d[\\d ]+$";
903
+ if (mobileNo.matches(regex)) {
914
904
  result = true;
915
905
  }
916
906
  } catch (Exception e) {
@@ -931,15 +921,28 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
931
921
  mLocationRequest1 = new LocationRequest();
932
922
  mLocationRequest1.setInterval(INTERVAL);
933
923
  mLocationRequest1.setFastestInterval(FASTEST_INTERVAL);
934
- mLocationRequest1.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
924
+ mLocationRequest1.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
935
925
  }
936
926
 
937
927
  protected void startLocationUpdates1() {
938
- Context context1 = cordova.getActivity().getApplicationContext();
939
- if (ActivityCompat.checkSelfPermission(context1, Manifest.permission.READ_PHONE_STATE) != PackageManager.PERMISSION_GRANTED) {
940
- //ActivityCompat.requestPermissions(cordova.getActivity(), new String[]{Manifest.permission.READ_PHONE_STATE}, 5);
928
+ boolean isPermissionGranted;
929
+ try {
930
+ Context context1 = cordova.getActivity().getApplicationContext();
931
+ if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
932
+ if (ActivityCompat.checkSelfPermission(context1, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context1, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
933
+ isPermissionGranted = false;
934
+ }else{
935
+ isPermissionGranted = true;
936
+ }
937
+ }else{
938
+ isPermissionGranted = true;
939
+ }
940
+ if(isPermissionGranted){
941
+ PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient1, mLocationRequest1, this);
942
+ }
943
+ } catch (Exception e) {
944
+ e.printStackTrace();
941
945
  }
942
- PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient1, mLocationRequest1, this);
943
946
  }
944
947
 
945
948
  public void scanQRCode(CallbackContext callbackContext) {
@@ -989,7 +992,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
989
992
  if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
990
993
  checkPermission = false;
991
994
  }
992
- };
995
+ }
993
996
  if (checkPermission) {
994
997
  list = new ArrayList<String>(Arrays.asList(permissions));
995
998
  permissions = list.toArray(new String[0]);
@@ -998,7 +1001,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
998
1001
  if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
999
1002
  permissionGranted = false;
1000
1003
  }
1001
- };
1004
+ }
1002
1005
  if (!permissionGranted) {
1003
1006
  callback.error("failure");
1004
1007
  } else {
@@ -1011,30 +1014,32 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1011
1014
  e.printStackTrace();
1012
1015
  }
1013
1016
  }
1017
+
1014
1018
  private void getLocationPermission(JSONArray args, CallbackContext callbackContext) {
1015
1019
  boolean permissionGranted = true;
1016
1020
  List<String> list;
1017
1021
  try {
1018
1022
  callback = callbackContext;
1019
1023
  Context context = cordova.getActivity().getApplicationContext();
1020
- String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
1021
- list = new ArrayList<String>(Arrays.asList(permissions));
1022
- permissions = list.toArray(new String[0]);
1024
+ String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
1025
+ list = new ArrayList<String>(Arrays.asList(permissions));
1026
+ permissions = list.toArray(new String[0]);
1023
1027
 
1024
- for (int i = 0; i < permissions.length; i++) {
1025
- if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
1026
- permissionGranted = false;
1027
- }
1028
- };
1029
- if (!permissionGranted) {
1030
- PermissionHelper.requestPermissions(this, 111, permissions);
1031
- } else {
1032
- callback.success("success");
1028
+ for (int i = 0; i < permissions.length; i++) {
1029
+ if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
1030
+ permissionGranted = false;
1033
1031
  }
1032
+ }
1033
+ if (!permissionGranted) {
1034
+ PermissionHelper.requestPermissions(this, 111, permissions);
1035
+ } else {
1036
+ callback.success("success");
1037
+ }
1034
1038
  } catch (Exception e) {
1035
1039
  e.printStackTrace();
1036
1040
  }
1037
1041
  }
1042
+
1038
1043
  private void getPermissions(JSONArray args, CallbackContext callbackContext) {
1039
1044
  boolean permissionGranted = true;
1040
1045
  List<String> list;
@@ -1047,12 +1052,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1047
1052
  list = new ArrayList<String>(Arrays.asList(permissions));
1048
1053
  list.remove("android.permission.ACCESS_BACKGROUND_LOCATION");
1049
1054
  permissions = list.toArray(new String[0]);
1050
- };
1055
+ }
1051
1056
  for (int i = 0; i < permissions.length; i++) {
1052
1057
  if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
1053
1058
  permissionGranted = false;
1054
1059
  }
1055
- };
1060
+ }
1056
1061
  if (!permissionGranted) {
1057
1062
  PermissionHelper.requestPermissions(this, 1, permissions);
1058
1063
  } else {
@@ -1065,6 +1070,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1065
1070
  e.printStackTrace();
1066
1071
  }
1067
1072
  }
1073
+
1068
1074
  public void captureImageLiveCamera(CallbackContext callbackContext) {
1069
1075
  callback = callbackContext;
1070
1076
  Context context = cordova.getActivity().getApplicationContext();
@@ -1140,15 +1146,15 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1140
1146
  callbackContext.sendPluginResult(pluginResult);
1141
1147
  }
1142
1148
 
1143
- private String getMimeType(String path,Uri uri) {
1149
+ private String getMimeType(String path, Uri uri) {
1144
1150
  String mimeType = null;
1145
- if(uri==null){
1151
+ if (uri == null) {
1146
1152
  String extension = MimeTypeMap.getFileExtensionFromUrl(path);
1147
1153
  if (extension != null) {
1148
1154
  MimeTypeMap mime = MimeTypeMap.getSingleton();
1149
1155
  mimeType = mime.getMimeTypeFromExtension(extension.toLowerCase());
1150
1156
  }
1151
- }else{
1157
+ } else {
1152
1158
  if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
1153
1159
  ContentResolver cr = cordova.getActivity().getContentResolver();
1154
1160
  mimeType = cr.getType(uri);
@@ -1158,7 +1164,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1158
1164
  mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
1159
1165
  fileExtension.toLowerCase());
1160
1166
  }
1161
- };
1167
+ }
1162
1168
  return mimeType;
1163
1169
  }
1164
1170
 
@@ -1197,7 +1203,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1197
1203
  OutputStream desFileWriter;
1198
1204
  byte[] buf;
1199
1205
  int srcFileSize;
1200
- String compressedImagePathStr = "";
1206
+ String compressedImagePathStr;
1201
1207
  String compressedImageName = "";
1202
1208
  Bitmap bitmap;
1203
1209
  BitmapFactory.Options options = new BitmapFactory.Options();
@@ -1210,10 +1216,10 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1210
1216
 
1211
1217
  File fileToCompress = new File(imageSourcePath);
1212
1218
  String thumbnail = getFileThumbnail(imageSourcePath, "." + imageSourcePath.substring(imageSourcePath.lastIndexOf(".") + 1).toLowerCase());
1213
- File compressedImageFile = null;
1219
+ File compressedImageFile;
1214
1220
 
1215
1221
  try {
1216
- compressedImageFile = new Compressor(cordova.getActivity())
1222
+ compressedImageFile = new Compressor(cordova.getActivity())
1217
1223
  .setQuality(15)
1218
1224
  .setCompressFormat(Bitmap.CompressFormat.JPEG)
1219
1225
  .compressToFile(fileToCompress);
@@ -1248,7 +1254,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1248
1254
  } else {
1249
1255
  bitmap = BitmapFactory.decodeFile(compressedImageFile.getAbsolutePath());
1250
1256
  }
1251
- String encodedImage = null;
1257
+ String encodedImage;
1252
1258
  try {
1253
1259
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1254
1260
  bitmap.compress(Bitmap.CompressFormat.JPEG, 15, outputStream);
@@ -1273,8 +1279,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1273
1279
  file.delete();
1274
1280
  }
1275
1281
  }
1276
- JSONObject fileProperities = null;
1277
- String imgFilePath, fileName, fileExtension = "";
1282
+ JSONObject fileProperities;
1283
+ String imgFilePath, fileName, fileExtension;
1278
1284
  imgFilePath = compressedImageName.substring(0, compressedImageName.lastIndexOf("/"));
1279
1285
  String[] fileName1 = compressedImageName.split("/");
1280
1286
  fileName = fileName1[fileName1.length - 1];
@@ -1306,9 +1312,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1306
1312
  }
1307
1313
 
1308
1314
 
1309
-
1310
- public void convertImageTo64BaseString1(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1311
- String compressedImagePathStr = "";
1315
+ public void convertImageTo64BaseString1(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1316
+ String compressedImagePathStr;
1312
1317
  String compressedImageName = "";
1313
1318
  String filePath = imageSourcePath;
1314
1319
  Bitmap scaledBitmap = null;
@@ -1318,7 +1323,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1318
1323
  options.inJustDecodeBounds = true;
1319
1324
  String[] bits = imageSourcePath.split("/");
1320
1325
 
1321
- String fileNameToSend = bits[bits.length-1];
1326
+ String fileNameToSend = bits[bits.length - 1];
1322
1327
  if (fileNameToSend.indexOf(".") > 0)
1323
1328
  fileNameToSend = fileNameToSend.substring(0, fileNameToSend.lastIndexOf("."));
1324
1329
  Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
@@ -1369,7 +1374,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1369
1374
  scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
1370
1375
  Canvas canvas = new Canvas(scaledBitmap);
1371
1376
  canvas.setMatrix(scaleMatrix);
1372
- canvas.drawBitmap(bmp, middleX - bmp.getWidth()/2, middleY - bmp.getHeight()/2, new Paint(Paint.FILTER_BITMAP_FLAG));
1377
+ canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));
1373
1378
  //check the rotation of the image and display it properly
1374
1379
  ExifInterface exif;
1375
1380
  try {
@@ -1393,11 +1398,11 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1393
1398
  }
1394
1399
  ByteArrayOutputStream baos = new ByteArrayOutputStream();
1395
1400
  try {
1396
- if(imgSrcType.equals("compress")) {
1401
+ if (imgSrcType.equals("compress")) {
1397
1402
  String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1398
- if(!destinationPath.equalsIgnoreCase("")){
1403
+ if (!destinationPath.equalsIgnoreCase("")) {
1399
1404
  compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + destinationPath;
1400
- }else{
1405
+ } else {
1401
1406
  compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images";
1402
1407
  }
1403
1408
  compressedImageName = compressedImagePathStr + "/" + fileNameToSend + "_" + timeStamp + ".jpg";
@@ -1406,16 +1411,19 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1406
1411
  fileSavedPath.mkdirs();
1407
1412
  }
1408
1413
  FileOutputStream out = new FileOutputStream(compressedImageName);
1409
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, out);
1414
+ if (scaledBitmap != null) {
1415
+ scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, out);
1416
+ }
1410
1417
  } else {
1411
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, baos);
1418
+ if (scaledBitmap != null) {
1419
+ scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, baos);
1420
+ }
1412
1421
  }
1413
- String encodedImage = null;
1422
+ String encodedImage;
1414
1423
  byte[] byteArray;
1415
1424
  try {
1416
1425
  byteArray = baos.toByteArray();
1417
1426
  encodedImage = Base64.encodeToString(byteArray, Base64.NO_WRAP);
1418
- imgSrcType = imgSrcType;
1419
1427
  if (imgSrcType.equals("camera")) {
1420
1428
  File file = new File(imageSourcePath);
1421
1429
  if (file.exists()) {
@@ -1428,14 +1436,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1428
1436
  callbackContext.success(encodedImage);
1429
1437
  } else if (imgSrcType.equals("compress")) {
1430
1438
  try {
1431
- if(!destinationPath.equalsIgnoreCase("")){
1439
+ if (!destinationPath.equalsIgnoreCase("")) {
1432
1440
  File file = new File(imageSourcePath);
1433
1441
  if (file.exists()) {
1434
1442
  file.delete();
1435
1443
  }
1436
1444
  }
1437
- JSONObject fileProperities = null;
1438
- String imgFilePath, fileName, fileExtension = "";
1445
+ JSONObject fileProperities;
1446
+ String imgFilePath, fileName, fileExtension;
1439
1447
  imgFilePath = compressedImageName.substring(0, compressedImageName.lastIndexOf("/"));
1440
1448
  String[] fileName1 = compressedImageName.split("/");
1441
1449
  fileName = fileName1[fileName1.length - 1];
@@ -1447,7 +1455,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1447
1455
  fileProperities.put("fileName", fileName);
1448
1456
  fileProperities.put("fileSize", fileSize);
1449
1457
  fileProperities.put("fileExtension", fileExtension);
1450
- fileProperities.put("thumbnail", getFileThumbnail(imgFilePath+ "/" +fileName, fileExtension));
1458
+ fileProperities.put("thumbnail", getFileThumbnail(imgFilePath + "/" + fileName, fileExtension));
1451
1459
  attachmentDestPath = "";
1452
1460
  callback.success(fileProperities);
1453
1461
  } catch (Exception e) {
@@ -1465,18 +1473,18 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1465
1473
  }
1466
1474
 
1467
1475
  public String getBase64String(String imageSourcePath) {
1468
- String resultString="";
1476
+ String resultString = "";
1469
1477
  String filePath = mInterfaceUtil.rootDirectory + "/" + imageSourcePath;
1470
1478
  File image = new File(filePath);
1471
1479
  BitmapFactory.Options bmOptions = new BitmapFactory.Options();
1472
- Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(),bmOptions);
1473
- try {
1474
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1475
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
1476
- resultString = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1477
- } catch (Exception e) {
1478
- e.printStackTrace();
1479
- }
1480
+ Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
1481
+ try {
1482
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1483
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
1484
+ resultString = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1485
+ } catch (Exception e) {
1486
+ e.printStackTrace();
1487
+ }
1480
1488
  return resultString;
1481
1489
  }
1482
1490
 
@@ -1492,6 +1500,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1492
1500
  callbackContext.error(e.getMessage());
1493
1501
  }
1494
1502
  }
1503
+
1495
1504
  public Intent getPickImageChooserIntent() {
1496
1505
  Intent openFile, selectFile;
1497
1506
  if (Build.MANUFACTURER.equals("samsung")) {
@@ -1506,6 +1515,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1506
1515
  selectFile = Intent.createChooser(openFile, "Select File");
1507
1516
  return selectFile;
1508
1517
  }
1518
+
1509
1519
  //App version plugin
1510
1520
  public void appVersion(CallbackContext callbackContext) {
1511
1521
  try {
@@ -1526,14 +1536,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1526
1536
  //Rotate Screen plugin
1527
1537
  public void rotateScreen(JSONArray args, CallbackContext callbackContext) {
1528
1538
  String orientation = args.optString(0);
1529
- String currentOrientation = "";
1539
+ String currentOrientation;
1530
1540
  Activity activity = cordova.getActivity();
1531
1541
  int orientation1 = activity.getResources().getConfiguration().orientation;
1532
1542
  if (orientation1 == Configuration.ORIENTATION_LANDSCAPE) {
1533
1543
  currentOrientation = "landscape";
1534
1544
  } else {
1535
1545
  currentOrientation = "portrait";
1536
- };
1546
+ }
1537
1547
  if (orientation.equals(ANY)) {
1538
1548
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1539
1549
  } else if (orientation.equals(LANDSCAPE_PRIMARY)) {
@@ -1572,6 +1582,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1572
1582
  r.put("applicationName", getApplicationName(cordova.getActivity()));
1573
1583
  callbackContext.success(r);
1574
1584
  }
1585
+
1575
1586
  public static String getApplicationName(Context context) {
1576
1587
  ApplicationInfo applicationInfo = context.getApplicationInfo();
1577
1588
  int stringId = applicationInfo.labelRes;
@@ -1618,7 +1629,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1618
1629
  }
1619
1630
  } else if (requestCode == PICK_IMAGE_FROM_GALLERY && callback != null) {
1620
1631
  if (resultCode == RESULT_OK) {
1621
- String fileName = null, getfilePath = null, filePath = null, fileType, storageDefinition, fileExtension;
1632
+ String fileName = null, getfilePath = null, filePath, fileType, storageDefinition, fileExtension;
1622
1633
  final String docId, type, id;
1623
1634
  final String[] split;
1624
1635
  final String tag, path;
@@ -1679,7 +1690,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1679
1690
  cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
1680
1691
  try {
1681
1692
  if (cursor != null && cursor.moveToFirst()) {
1682
- fileName = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
1693
+ int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
1694
+ if (displayNameIndex != -1) {
1695
+ fileName = cursor.getString(displayNameIndex);
1696
+ } else {
1697
+ fileName = "";
1698
+ }
1683
1699
  }
1684
1700
  } finally {
1685
1701
  cursor.close();
@@ -1711,17 +1727,17 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1711
1727
  if (filePath != null) {
1712
1728
  try {
1713
1729
  if (fileExtension.equals(".heic")) {
1714
- if(galleryAttachmentInd.equals("true")){
1715
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress",attachmentDestPath);
1716
- }else{
1717
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery","");
1730
+ if (galleryAttachmentInd.equals("true")) {
1731
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1732
+ } else {
1733
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
1718
1734
  }
1719
1735
 
1720
1736
  } else if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
1721
- if(galleryAttachmentInd.equals("true")){
1722
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress",attachmentDestPath);
1723
- }else{
1724
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery","");
1737
+ if (galleryAttachmentInd.equals("true")) {
1738
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1739
+ } else {
1740
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
1725
1741
  }
1726
1742
  } else {
1727
1743
  callback.error("Only JPEG or PNG file extensions are allowed to attach.");
@@ -1740,16 +1756,16 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1740
1756
  } else {
1741
1757
  callback.error(resultCode);
1742
1758
  }
1743
- } else if(requestCode == NEW_FILE_PICK_REQUEST && callback != null) {
1759
+ } else if (requestCode == NEW_FILE_PICK_REQUEST && callback != null) {
1744
1760
  try {
1745
1761
  Uri uri = data.getData();
1746
- String fileName = null, extension = null, filePath = null;
1747
- JSONObject fileProperities = null;
1762
+ String fileName, extension, filePath;
1763
+ JSONObject fileProperities;
1748
1764
  Cursor cursor = null;
1749
1765
  if (uri.getScheme().equals("file")) {
1750
1766
  fileName = uri.getLastPathSegment();
1751
1767
 
1752
- if (fileName.indexOf(".") > 0){
1768
+ if (fileName.indexOf(".") > 0) {
1753
1769
  fileName = fileName.substring(0, fileName.lastIndexOf("."));
1754
1770
  String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1755
1771
  extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
@@ -1757,9 +1773,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1757
1773
  }
1758
1774
  } else {
1759
1775
  try {
1760
- cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri, new String[]{ MediaStore.Images.ImageColumns.DISPLAY_NAME }, null, null, null);
1776
+ cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DISPLAY_NAME}, null, null, null);
1761
1777
  if (cursor != null && cursor.moveToFirst()) {
1762
- fileName = cursor.getString(cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME));
1778
+ int displayNameIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME);
1779
+ if (displayNameIndex != -1) {
1780
+ fileName = cursor.getString(displayNameIndex);
1781
+ } else {
1782
+ fileName = "";
1783
+ }
1763
1784
  extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1764
1785
  if (!extension.equals(".jpeg") && !extension.equals(".jpg") && !extension.equals(".png")) {
1765
1786
  String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
@@ -1767,7 +1788,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1767
1788
  fileName = fileName + "_" + timeStamp + extension;
1768
1789
  }
1769
1790
 
1770
- }else{
1791
+ } else {
1771
1792
  fileName = uri.getLastPathSegment();
1772
1793
  }
1773
1794
  } finally {
@@ -1779,19 +1800,19 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1779
1800
 
1780
1801
  extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1781
1802
 
1782
- filePath = copyFileFromUri(cordova.getActivity().getApplicationContext(), uri, fileName, attachmentDestPath,callback);
1803
+ filePath = copyFileFromUri(cordova.getActivity().getApplicationContext(), uri, fileName, attachmentDestPath, callback);
1783
1804
  File file = new File(filePath);
1784
- String mimeType = getMimeType(filePath,uri);
1805
+ String mimeType = getMimeType(filePath, uri);
1785
1806
  System.out.println("Mime type is: " + mimeType);
1786
1807
  double fileSize = file.length();
1787
1808
  if (filePath != null) {
1788
1809
  try {
1789
- if(requestCode == NEW_FILE_PICK_REQUEST) {
1790
- if(extension.equals(".heic")) {
1791
- convertImageTo64BaseString(callback, filePath, "compress",attachmentDestPath);
1810
+ if (requestCode == NEW_FILE_PICK_REQUEST) {
1811
+ if (extension.equals(".heic")) {
1812
+ convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
1792
1813
  } else if (mimeType != null) {
1793
1814
  if (mimeType.contains("image")) {
1794
- convertImageTo64BaseString(callback, filePath, "compress",attachmentDestPath);
1815
+ convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
1795
1816
  } else {
1796
1817
  fileProperities = new JSONObject();
1797
1818
  fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
@@ -1823,14 +1844,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1823
1844
  }
1824
1845
  } else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
1825
1846
  if (resultCode == RESULT_OK) {
1826
- if(cameraAttachmentInd.equals("true")){
1847
+ if (cameraAttachmentInd.equals("true")) {
1827
1848
  convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
1828
- }else{
1829
- convertImageTo64BaseString(callback, pictureFilePath, "camera","");
1849
+ } else {
1850
+ convertImageTo64BaseString(callback, pictureFilePath, "camera", "");
1830
1851
  }
1831
1852
 
1832
1853
  } else if (resultCode == Activity.RESULT_CANCELED) {
1833
- // TODO NO_RESULT or error callback?
1834
1854
  File file = new File(pictureFilePath);
1835
1855
  if (file.exists()) {
1836
1856
  file.delete();
@@ -1841,9 +1861,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1841
1861
  }
1842
1862
  } else if (requestCode == REQUEST_LIVE_IMAGE_CAPTURE && callback != null) {
1843
1863
  if (resultCode == RESULT_OK) {
1844
- convertImageTo64BaseString(callback, pictureFilePath, "compress",attachmentDestPath);
1864
+ convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
1845
1865
  } else if (resultCode == Activity.RESULT_CANCELED) {
1846
- // TODO NO_RESULT or error callback?
1847
1866
  File file = new File(pictureFilePath);
1848
1867
  if (file.exists()) {
1849
1868
  file.delete();
@@ -1856,12 +1875,11 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1856
1875
  if (resultCode == RESULT_OK) {
1857
1876
  String fileName = null,
1858
1877
  getfilePath = null,
1859
- filePath = null,
1878
+ filePath,
1860
1879
  fileExtension,
1861
1880
  fileType,
1862
1881
  fileSize = null,
1863
1882
  storageDefinition;
1864
- ;
1865
1883
  final String docId,
1866
1884
  type,
1867
1885
  id;
@@ -1871,7 +1889,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1871
1889
  final int splitIndex;
1872
1890
  Cursor cursor;
1873
1891
  long getSize;
1874
- JSONObject fileProperities = null;
1892
+ JSONObject fileProperities;
1875
1893
  Uri uri = data.getData(); //get uri for selected file
1876
1894
  fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
1877
1895
  File getFileName,
@@ -1930,10 +1948,18 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1930
1948
  cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
1931
1949
  try {
1932
1950
  if (cursor != null && cursor.moveToFirst()) {
1933
- fileName = cursor.getString(
1934
- cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
1935
- if (!cursor.isNull(cursor.getColumnIndex(OpenableColumns.SIZE))) {
1936
- fileSize = cursor.getString(cursor.getColumnIndex(OpenableColumns.SIZE));
1951
+ int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
1952
+ if (displayNameIndex != -1) {
1953
+ fileName = cursor.getString(displayNameIndex);
1954
+ } else {
1955
+ fileName = "";
1956
+ }
1957
+
1958
+ int fileSizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
1959
+ if (!cursor.isNull(fileSizeIndex) && fileSizeIndex != -1) {
1960
+ fileSize = cursor.getString(fileSizeIndex);
1961
+ } else {
1962
+ fileSize = "0";
1937
1963
  }
1938
1964
  }
1939
1965
  } finally {
@@ -1970,7 +1996,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1970
1996
  if (filePath != null) {
1971
1997
  try {
1972
1998
  if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
1973
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress",attachmentDestPath);
1999
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1974
2000
  } else {
1975
2001
  fileProperities = new JSONObject();
1976
2002
  fileProperities.put("filePath", filePath);
@@ -1989,7 +2015,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1989
2015
  e.printStackTrace();
1990
2016
  }
1991
2017
  } else if (resultCode == Activity.RESULT_CANCELED) {
1992
- // TODO NO_RESULT or error callback?
1993
2018
  callback.error("failure");
1994
2019
  } else {
1995
2020
  callback.error(resultCode);
@@ -2022,32 +2047,33 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2022
2047
  e.printStackTrace();
2023
2048
  }
2024
2049
  }
2050
+
2025
2051
  public String copyFileFromUri(Context context, Uri fileUri, String fileName, String destinationPath, CallbackContext callback) {
2026
- InputStream inputStream = null;
2027
- OutputStream outputStream = null;
2052
+ InputStream inputStream;
2053
+ OutputStream outputStream;
2028
2054
  String outPutFilePath = null;
2029
2055
  File saveDirectory;
2030
2056
  try {
2031
2057
  ContentResolver content = context.getContentResolver();
2032
2058
  inputStream = content.openInputStream(fileUri);
2033
2059
  File root = mInterfaceUtil.rootDirectory;
2034
- if(root == null) {
2060
+ if (root == null) {
2035
2061
  System.out.println("Failed to get root");
2036
2062
  }
2037
- if(!destinationPath.equalsIgnoreCase("")){
2063
+ if (!destinationPath.equalsIgnoreCase("")) {
2038
2064
  saveDirectory = new File(mInterfaceUtil.rootDirectory + "/" + destinationPath);
2039
- }else{
2065
+ } else {
2040
2066
  saveDirectory = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images");
2041
2067
  }
2042
2068
 
2043
2069
  saveDirectory.mkdirs();
2044
2070
  outPutFilePath = saveDirectory + "/" + fileName;
2045
2071
  outputStream = new FileOutputStream(outPutFilePath);
2046
- if(outputStream != null) {
2072
+ if (outputStream != null) {
2047
2073
  byte[] buffer = new byte[1000];
2048
2074
  int bytesRead = 0;
2049
- while ((bytesRead = inputStream.read( buffer, 0, buffer.length )) >= 0) {
2050
- outputStream.write( buffer, 0, buffer.length );
2075
+ while ((bytesRead = inputStream.read(buffer, 0, buffer.length)) >= 0) {
2076
+ outputStream.write(buffer, 0, buffer.length);
2051
2077
  }
2052
2078
  } else {
2053
2079
  callback.error("Error occurred in opening outputStream");
@@ -2057,6 +2083,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2057
2083
  }
2058
2084
  return outPutFilePath;
2059
2085
  }
2086
+
2060
2087
  /* CHECKING THE BACKGROUND SERVICE RUNNING OR NOT */
2061
2088
  private boolean isServiceRunning(Class<?> serviceClass) {
2062
2089
  ActivityManager manager = (ActivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
@@ -2086,7 +2113,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2086
2113
  .addOnConnectionFailedListener(this).build();
2087
2114
  mGoogleApiClient1.connect();
2088
2115
  LocationRequest locationRequest = LocationRequest.create();
2089
- locationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
2116
+ locationRequest.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
2090
2117
  locationRequest.setInterval(30 * 1000);
2091
2118
  locationRequest.setFastestInterval(5 * 1000);
2092
2119
  LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
@@ -2133,13 +2160,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2133
2160
  }
2134
2161
 
2135
2162
  @Override
2136
- public void onLocationChanged(Location location) {
2163
+ public void onLocationChanged(@NonNull Location location) {
2137
2164
  mCurrentLocation1 = location;
2138
2165
  try {
2139
- System.out.println(String.valueOf(mCurrentLocation1.getLatitude()) + "," + String.valueOf(mCurrentLocation1.getLongitude()));
2166
+ System.out.println(mCurrentLocation1.getLatitude() + "," + mCurrentLocation1.getLongitude());
2140
2167
  if (currentLocationInd.equals("true")) {
2141
2168
  currentLocationInd = "";
2142
- callback.success(String.valueOf(mCurrentLocation1.getLatitude()) + "," + String.valueOf(mCurrentLocation1.getLongitude()));
2169
+ callback.success(mCurrentLocation1.getLatitude() + "," + mCurrentLocation1.getLongitude());
2143
2170
  }
2144
2171
  } catch (Exception e) {
2145
2172
  callback.error(e.getMessage());
@@ -2148,8 +2175,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2148
2175
 
2149
2176
  private class DownloadTask extends AsyncTask<String, Integer, String> {
2150
2177
 
2151
- private Context context;
2152
- private PowerManager.WakeLock mWakeLock;
2178
+ private final Context context;
2153
2179
 
2154
2180
  public DownloadTask(Context context) {
2155
2181
  this.context = context;
@@ -2157,9 +2183,9 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2157
2183
 
2158
2184
  @Override
2159
2185
  protected String doInBackground(String... sUrl) {
2160
- InputStream input = null;
2161
- OutputStream output = null;
2162
- HttpURLConnection connection = null;
2186
+ InputStream input;
2187
+ OutputStream output;
2188
+ HttpURLConnection connection;
2163
2189
  try {
2164
2190
  URL url = new URL(sUrl[0]);
2165
2191
  connection = (HttpURLConnection) url.openConnection();
@@ -2181,7 +2207,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2181
2207
  }
2182
2208
  File fileSavePath = new File(rootPath + "/" + sUrl[1]);
2183
2209
  output = new FileOutputStream(fileSavePath);
2184
- byte data[] = new byte[4096];
2210
+ byte[] data = new byte[4096];
2185
2211
  long total = 0;
2186
2212
  int count;
2187
2213
  while ((count = input.read(data)) != -1) {
@@ -2199,10 +2225,10 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2199
2225
  } catch (Exception e) {
2200
2226
  callback.error("Failure..." + e.getMessage());
2201
2227
  }
2202
- if(sUrl[2].equalsIgnoreCase("true")){
2228
+ if (sUrl[2].equalsIgnoreCase("true")) {
2203
2229
  return sUrl[1];
2204
- }else{
2205
- return null;
2230
+ } else {
2231
+ return null;
2206
2232
  }
2207
2233
  }
2208
2234
 
@@ -2210,14 +2236,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2210
2236
  protected void onPostExecute(String result) {
2211
2237
  try {
2212
2238
  if (result != null) {
2213
- if(result.indexOf('.') != -1){
2214
- String extension = "." + result.substring(result.lastIndexOf(".") + 1).toLowerCase(),
2215
- filePath = mInterfaceUtil.rootDirectory+"/"+result;
2216
- String thumbnail = getFileThumbnail(filePath,extension);
2217
- callback.success(thumbnail);
2218
- } else{
2219
- callback.error("Failure...");
2220
- }
2239
+ if (result.indexOf('.') != -1) {
2240
+ String extension = "." + result.substring(result.lastIndexOf(".") + 1).toLowerCase(),
2241
+ filePath = mInterfaceUtil.rootDirectory + "/" + result;
2242
+ String thumbnail = getFileThumbnail(filePath, extension);
2243
+ callback.success(thumbnail);
2244
+ } else {
2245
+ callback.error("Failure...");
2246
+ }
2221
2247
  } else {
2222
2248
  System.out.println("success");
2223
2249
  callback.success("");
@@ -2227,7 +2253,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2227
2253
  }
2228
2254
  }
2229
2255
  }
2230
-
2256
+
2231
2257
  public static String pathComponent(String filename) {
2232
2258
  int i = filename.lastIndexOf(File.separator);
2233
2259
  return (i > -1) ? filename.substring(0, i) : filename;
@@ -2250,7 +2276,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2250
2276
  // Accept a path or a URI for the source zip.
2251
2277
  File root = mInterfaceUtil.rootDirectory;
2252
2278
  //callbackContext.success("file://"+root+"/");
2253
- Uri uri = null;
2254
2279
  Uri zipUri = getUriForArg(root + "/" + zipFileName);
2255
2280
  Uri outputUri = getUriForArg(root + "/" + outputDirectory);
2256
2281
  CordovaResourceApi resourceApi = webView.getResourceApi();
@@ -2287,7 +2312,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2287
2312
  e.printStackTrace();
2288
2313
  callbackContext.error("Bad zip file");
2289
2314
  return;
2290
- };
2315
+ }
2291
2316
  if (ze.isDirectory()) {
2292
2317
  File dir = new File(outputDirectory + compressedName);
2293
2318
  dir.mkdirs();
@@ -2319,10 +2344,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2319
2344
  try {
2320
2345
  inputStream.close();
2321
2346
  } catch (IOException e) {
2347
+ e.printStackTrace();
2322
2348
  }
2323
2349
  }
2324
2350
  }
2325
2351
  }
2352
+
2326
2353
  private void ensureZipPathSafety(final File outputFile, final String destDirectory) throws Exception {
2327
2354
  String destDirCanonicalPath = (new File(destDirectory)).getCanonicalPath();
2328
2355
  String outputFileCanonicalPath = outputFile.getCanonicalPath();
@@ -2340,43 +2367,39 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2340
2367
 
2341
2368
 
2342
2369
  public boolean isConnected() {
2343
- ConnectivityManager online = (ConnectivityManager)cordova.getActivity().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
2370
+ ConnectivityManager online = (ConnectivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
2344
2371
  NetworkInfo networkInfo = online.getActiveNetworkInfo();
2345
- if (networkInfo != null && networkInfo.isConnected()) {
2346
- return true;
2347
- } else {
2348
- return false;
2349
- }
2372
+ return networkInfo != null && networkInfo.isConnected();
2350
2373
  }
2351
2374
 
2352
2375
 
2353
- public String getFileThumbnail(String filePath,String extension){
2376
+ public String getFileThumbnail(String filePath, String extension) {
2354
2377
  Bitmap thumb;
2355
2378
  String imgString = "";
2356
2379
  try {
2357
- if(extension.equalsIgnoreCase(".mp4")){
2380
+ if (extension.equalsIgnoreCase(".mp4")) {
2358
2381
  thumb = ThumbnailUtils.createVideoThumbnail(filePath,
2359
2382
  MediaStore.Images.Thumbnails.MINI_KIND);
2360
2383
  imgString = convertBitmapToString(thumb);
2361
- }else if(extension.equalsIgnoreCase(".heic") || extension.equalsIgnoreCase(".jpeg")|| extension.equalsIgnoreCase(".jpg")|| extension.equalsIgnoreCase(".png")){
2384
+ } else if (extension.equalsIgnoreCase(".heic") || extension.equalsIgnoreCase(".jpeg") || extension.equalsIgnoreCase(".jpg") || extension.equalsIgnoreCase(".png")) {
2362
2385
  thumb = ThumbnailUtils.extractThumbnail(BitmapFactory.decodeFile(filePath),
2363
2386
  76, 76);
2364
2387
 
2365
2388
  imgString = convertBitmapToString(thumb);
2366
- }else if(extension.equalsIgnoreCase(".mp3")){
2389
+ } else if (extension.equalsIgnoreCase(".mp3")) {
2367
2390
  MediaMetadataRetriever mmr = new MediaMetadataRetriever();
2368
2391
  byte[] bytes;
2369
- BitmapFactory.Options bfo=new BitmapFactory.Options();
2392
+ BitmapFactory.Options bfo = new BitmapFactory.Options();
2370
2393
 
2371
2394
  mmr.setDataSource(cordova.getActivity().getApplicationContext(), Uri.fromFile(new File(filePath)));
2372
2395
  bytes = mmr.getEmbeddedPicture();
2373
- if (bytes != null){
2396
+ if (bytes != null) {
2374
2397
  thumb = BitmapFactory.decodeByteArray(bytes, 0, bytes.length, bfo);
2375
2398
  imgString = convertBitmapToString(thumb);
2376
2399
  }
2377
2400
  }
2378
- }catch (Exception e){
2379
-
2401
+ } catch (Exception e) {
2402
+ e.printStackTrace();
2380
2403
  }
2381
2404
  return imgString;
2382
2405
  }