cordova-plugin-mserviceinterface-2.0 1.0.63 → 1.0.65

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cordova-plugin-mserviceinterface-2.0",
3
- "version": "1.0.63",
3
+ "version": "1.0.65",
4
4
  "description": "This plugin establishes the connection to the native interface and performs the requested task.",
5
5
  "main": "index.js",
6
6
  "scripts": {
package/plugin.xml CHANGED
@@ -2,7 +2,7 @@
2
2
  <plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
3
3
  xmlns:android="http://schemas.android.com/apk/res/android"
4
4
  id="cordova-plugin-mserviceinterface-2.0"
5
- version="1.0.63">
5
+ version="1.0.65">
6
6
  <name>mserviceinterface-2.0</name>
7
7
  <description>This plugin establishes the connection to the native interface and performs the requested task.</description>
8
8
  <author>selfservit@gmail.com</author>
@@ -124,7 +124,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
124
124
  private static final String PORTRAIT = "portrait";
125
125
  private static final String LANDSCAPE = "landscape";
126
126
  private static final String ANDROID_PLATFORM = "Android";
127
-
128
127
  String currentLocationInd = "";
129
128
  Location mCurrentLocation1;
130
129
  LocationRequest mLocationRequest1;
@@ -157,8 +156,9 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
157
156
  if (mInterfaceUtil.packageName.equals("")) {
158
157
  mInterfaceUtil.packageName = cordova.getActivity().getApplicationContext().getPackageName().split("\\.")[2];
159
158
  }
160
- /* START BACKGROUND SERVICE IF NOT RUNNING ALREADY */
161
- if (action.equals("StartService")) {
159
+ if (action.equals("AppCleanUp")) {
160
+ mInterfaceUtil.appCleanUp(callbackContext, cordova.getActivity().getApplicationContext());
161
+ } else if (action.equals("StartService")) {
162
162
  try {
163
163
  boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
164
164
  System.out.println("appInfoUpdated: " + appInfoUpdated);
@@ -173,8 +173,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
173
173
  }
174
174
  callbackContext.success("Success");
175
175
  } catch (Exception e) {
176
- System.out.println("StartService Exception is: " + e.getMessage());
177
- callbackContext.error(e.getMessage());
176
+ System.out.println("Unable to StartService, Exception is: " + e.getMessage());
177
+ callbackContext.error("Unable to StartService, Exception is: " + e.getMessage());
178
178
  }
179
179
  } else if (action.equals("showToastWithOptions")) {
180
180
  try {
@@ -184,7 +184,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
184
184
  Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_SHORT).show();
185
185
  }
186
186
  } catch (Exception exception) {
187
- callbackContext.success(exception.getMessage());
187
+ callbackContext.error("showToastWithOptions: "+ exception.getMessage());
188
188
  }
189
189
  } else if (action.equals("CheckLocationAccuracy")) {
190
190
  int locationInt;
@@ -192,16 +192,16 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
192
192
  locationInt = Settings.Secure.getInt(this.cordova.getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);
193
193
  callbackContext.success(Integer.toString(locationInt));
194
194
  } catch (Settings.SettingNotFoundException e) {
195
- System.out.println("Exception is: " + e.getMessage());
196
- callbackContext.error(e.getMessage());
195
+ System.out.println("unable to check location accuracy: Exception is: " + e.getMessage());
196
+ callbackContext.error("unable to check location accuracy: Exception is: " + e.getMessage());
197
197
  }
198
198
  } else if (action.equals("GetBase64String")) {
199
199
  try {
200
200
  String imageString = getBase64String(args.getJSONObject(0).optString("filePath"));
201
201
  callbackContext.success(imageString);
202
202
  } catch (Exception e) {
203
- System.out.println("Exception is: " + e.getMessage());
204
- callbackContext.error(e.getMessage());
203
+ System.out.println("Unable to get Base 64 string: Exception is: " + e.getMessage());
204
+ callbackContext.error("Unable to get Base 64 string: Exception is: " + e.getMessage());
205
205
  }
206
206
  } else if (action.equals("GetFCMUtils")) {
207
207
  try {
@@ -218,7 +218,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
218
218
  callbackContext.error("Error occurred");
219
219
  }
220
220
  } catch (Exception e) {
221
- System.out.println("Exception is: " + e.getMessage());
221
+ System.out.println("GetFCMUtils: Exception is: " + e.getMessage());
222
222
  callbackContext.error(e.getMessage());
223
223
  }
224
224
  } else if (action.equals("GetSyncIndicator")) {
@@ -579,7 +579,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
579
579
  try {
580
580
  new mInterfaceUtil().readFile(args, callbackContext);
581
581
  } catch (Exception e) {
582
- callbackContext.error(e.getMessage());
582
+ callbackContext.error("ReadFile failed, exception is : "+e.getMessage());
583
583
  }
584
584
  return true;
585
585
  } else if (action.equals("DeleteFile")) {
@@ -713,7 +713,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
713
713
  cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + cordova.getActivity().getApplicationContext().getPackageName())));
714
714
  callbackContext.success("success");
715
715
  } catch (Exception e) {
716
- callbackContext.error(e.getMessage());
716
+ callbackContext.error("UpdateNew failed, exception is : "+e.getMessage());
717
717
  }
718
718
  } else if (action.equals("OpenFileWithViewer")) {
719
719
  try {
@@ -733,7 +733,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
733
733
  cordova.getActivity().startActivity(intent);
734
734
  callbackContext.success();
735
735
  } catch (Exception e) {
736
- callbackContext.error(e.getMessage());
736
+ callbackContext.error("OpenFileWithViewer failed, exception is : "+e.getMessage());
737
737
  }
738
738
  } else if (action.equals("CaptureImageFromCamera")) {
739
739
  try {
@@ -744,7 +744,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
744
744
  captureImage(callbackContext);
745
745
  return true;
746
746
  } catch (Exception e) {
747
- callbackContext.error(e.getMessage());
747
+ callbackContext.error("CaptureImageFromCamera failed, exception is : "+e.getMessage());
748
748
  }
749
749
  } else if (action.equals("PickImageFromGallery")) {
750
750
  try {
@@ -755,7 +755,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
755
755
  pickImageFromGallery(callbackContext);
756
756
  return true;
757
757
  } catch (Exception e) {
758
- callbackContext.error(e.getMessage());
758
+ callbackContext.error("PickImageFromGallery failed, exception is : "+e.getMessage());
759
759
  }
760
760
  } else if (action.equals("CaptureFromCamera")) {
761
761
  try {
@@ -784,7 +784,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
784
784
  final DownloadTask downloadTask = new DownloadTask(cordova.getActivity(), callback);
785
785
  downloadTask.execute(args.optJSONObject(0).optString("url"), args.optJSONObject(0).optString("filePath"), args.optJSONObject(0).optString("thumbnailInd"));
786
786
  } catch (Exception e) {
787
- callbackContext.error(e.getMessage());
787
+ callbackContext.error("DownloadFile failed for "+args.optJSONObject(0).optString("url")+", exception is : "+e.getMessage());
788
788
  }
789
789
  return true;
790
790
  } else if ("QueueProcessor".equals(action)) {
@@ -795,14 +795,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
795
795
  scanQRCode(callbackContext);
796
796
  return true;
797
797
  } catch (Exception e) {
798
- callbackContext.error(e.getMessage());
798
+ callbackContext.error("ScanQRCode failed, exception is : "+e.getMessage());
799
799
  }
800
800
  } else if (action.equals("ScanBarCode")) {
801
801
  try {
802
802
  scanBarCode(callbackContext);
803
803
  return true;
804
804
  } catch (Exception e) {
805
- callbackContext.error(e.getMessage());
805
+ callbackContext.error("ScanBarCode failed, exception is : "+e.getMessage());
806
806
  }
807
807
  } else if (action.equals("GetSubDirectoryList")) {
808
808
  new mInterfaceUtil().getSubDirectoryList(args, callbackContext);
@@ -821,7 +821,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
821
821
  callbackContext.success("");
822
822
  }
823
823
  } catch (Exception e) {
824
- callbackContext.error(e.getMessage());
824
+ callbackContext.error("GetAppStateInfo failed, exception is : "+e.getMessage());
825
825
  }
826
826
  return true;
827
827
  } else if (action.equals("UpdateAppInfo")) {
@@ -833,7 +833,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
833
833
  callbackContext.error("failed to update app info");
834
834
  }
835
835
  } catch (Exception e) {
836
- callbackContext.error(e.getMessage());
836
+ callbackContext.error("UpdateAppInfo failed, exception is : "+e.getMessage());
837
837
  }
838
838
  return true;
839
839
  } else if (action.equals("MoveFile")) {
@@ -851,6 +851,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
851
851
  Intent smsIntent;
852
852
  PluginResult result;
853
853
  try {
854
+ callback = callbackContext;
854
855
  contact_number = args.getJSONObject(0).optString("contact_number");
855
856
  if (contact_number != null) {
856
857
  if (!contact_number.equals("")) {
@@ -875,7 +876,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
875
876
  }
876
877
  } catch (JSONException e) {
877
878
  e.printStackTrace();
878
- result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
879
+ result = new PluginResult(PluginResult.Status.ERROR, "OpenSms failed, exception is : "+e.getMessage());
879
880
  callback.sendPluginResult(result);
880
881
  }
881
882
  return true;
@@ -883,6 +884,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
883
884
  Intent intent;
884
885
  PluginResult result;
885
886
  try {
887
+ callback = callbackContext;
886
888
  String contact_number = args.getJSONObject(0).optString("contact_number");
887
889
  if (contact_number != null) {
888
890
  if (!contact_number.equals("")) {
@@ -915,6 +917,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
915
917
  PluginResult result;
916
918
  String toEmail, ccEmail, subject, body, mailto;
917
919
  try {
920
+ callback = callbackContext;
918
921
  toEmail = args.getJSONObject(0).optString("toEmail");
919
922
  ccEmail = args.getJSONObject(0).optString("ccEmail");
920
923
  subject = args.getJSONObject(0).optString("subject");
@@ -944,7 +947,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
944
947
  }
945
948
  } catch (Exception e) {
946
949
  e.printStackTrace();
947
- result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
950
+ result = new PluginResult(PluginResult.Status.ERROR, "OpenEmail failed, exception is : "+e.getMessage());
948
951
  callback.sendPluginResult(result);
949
952
  }
950
953
 
@@ -958,13 +961,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
958
961
  callbackContext.success("success");
959
962
  } catch (Exception e) {
960
963
  e.printStackTrace();
961
- result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
964
+ result = new PluginResult(PluginResult.Status.ERROR, "copyAttachmentFile failed, exception is : "+e.getMessage());
962
965
  callback.sendPluginResult(result);
963
966
  }
964
967
 
965
968
  }
966
969
  } catch (JSONException e) {
967
- System.out.println("execute: " + e.getMessage());
970
+ System.out.println(" unable to proccess plugin method, exception is : "+e.getMessage());
968
971
  }
969
972
  return true;
970
973
  }
@@ -973,7 +976,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
973
976
  String regex;
974
977
  boolean result = false;
975
978
  try {
976
- regex = "^\\+?\\d[\\d ]+$";
979
+ regex = "^\\+?-?\\d(\\d|[ -](?!\\s))+$";
977
980
  if (mobileNo.matches(regex)) {
978
981
  result = true;
979
982
  }
@@ -1044,7 +1047,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1044
1047
  pluginResult.setKeepCallback(true);
1045
1048
  callbackContext.sendPluginResult(pluginResult);
1046
1049
  } catch (Exception e) {
1047
- callbackContext.error(e.getMessage());
1050
+ callbackContext.error("scanQRCode failed, exception is : "+e.getMessage());
1048
1051
  }
1049
1052
  }
1050
1053
 
@@ -1064,7 +1067,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1064
1067
  pluginResult.setKeepCallback(true);
1065
1068
  callbackContext.sendPluginResult(pluginResult);
1066
1069
  } catch (Exception e) {
1067
- callbackContext.error(e.getMessage());
1070
+ callbackContext.error("scanBarCode failed, exception is : "+e.getMessage());
1068
1071
  }
1069
1072
  }
1070
1073
 
@@ -1072,7 +1075,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1072
1075
  try {
1073
1076
  callbackContext.success("file://" + mInterfaceUtil.rootDirectory + "/");
1074
1077
  } catch (Exception e) {
1075
- callbackContext.error(e.getMessage());
1078
+ callbackContext.error("getStorageRoot failed, exception is : "+e.getMessage());
1076
1079
  }
1077
1080
  }
1078
1081
 
@@ -1168,7 +1171,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1168
1171
  callback.success("success");
1169
1172
  }
1170
1173
  } catch (Exception e) {
1171
- callback.error(e.getMessage());
1174
+ callback.error("getPermissions failed, exception is : "+e.getMessage());
1172
1175
  }
1173
1176
  }
1174
1177
 
@@ -1244,7 +1247,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1244
1247
  pluginResult.setKeepCallback(true);
1245
1248
  callbackContext.sendPluginResult(pluginResult);
1246
1249
  } catch (Exception e) {
1247
- callbackContext.error(e.getMessage());
1250
+ callbackContext.error("pickImageFromGallery failed, exception is : "+e.getMessage());
1248
1251
  }
1249
1252
  }
1250
1253
 
@@ -1410,12 +1413,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1410
1413
  callback.success(fileProperities);
1411
1414
  } catch (Exception e) {
1412
1415
  attachmentDestPath = "";
1413
- callback.error(e.getMessage());
1416
+ callback.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
1414
1417
  }
1415
1418
  }
1416
1419
  } catch (Exception e) {
1417
1420
  attachmentDestPath = "";
1418
- callbackContext.error(e.getMessage());
1421
+ callbackContext.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
1419
1422
  }
1420
1423
 
1421
1424
  } catch (Exception e) {
@@ -1424,167 +1427,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1424
1427
 
1425
1428
  }
1426
1429
 
1427
-
1428
- public void convertImageTo64BaseString1(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1429
- String compressedImagePathStr;
1430
- String compressedImageName = "";
1431
- String filePath = imageSourcePath;
1432
- Bitmap scaledBitmap = null;
1433
- BitmapFactory.Options options = new BitmapFactory.Options();
1434
- //by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If
1435
- //you try the use the bitmap here, you will get null.
1436
- options.inJustDecodeBounds = true;
1437
- String[] bits = imageSourcePath.split("/");
1438
-
1439
- String fileNameToSend = bits[bits.length - 1];
1440
- if (fileNameToSend.indexOf(".") > 0)
1441
- fileNameToSend = fileNameToSend.substring(0, fileNameToSend.lastIndexOf("."));
1442
- Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
1443
- int actualHeight = options.outHeight;
1444
- int actualWidth = options.outWidth;
1445
- //max Height and width values of the compressed image is taken as 816x612
1446
- float maxHeight = 816.0f;
1447
- float maxWidth = 612.0f;
1448
- float imgRatio = actualWidth / actualHeight;
1449
- float maxRatio = maxWidth / maxHeight;
1450
- //width and height values are set maintaining the aspect ratio of the image
1451
- if (actualHeight > maxHeight || actualWidth > maxWidth) {
1452
- if (imgRatio < maxRatio) {
1453
- imgRatio = maxHeight / actualHeight;
1454
- actualWidth = (int) (imgRatio * actualWidth);
1455
- actualHeight = (int) maxHeight;
1456
- } else if (imgRatio > maxRatio) {
1457
- imgRatio = maxWidth / actualWidth;
1458
- actualHeight = (int) (imgRatio * actualHeight);
1459
- actualWidth = (int) maxWidth;
1460
- } else {
1461
- actualHeight = (int) maxHeight;
1462
- actualWidth = (int) maxWidth;
1463
- }
1464
- }
1465
- options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight);
1466
- options.inJustDecodeBounds = false;
1467
- //this options allow android to claim the bitmap memory if it runs low on memory
1468
- options.inPurgeable = true;
1469
- options.inInputShareable = true;
1470
- options.inTempStorage = new byte[16 * 1024];
1471
- try {
1472
- //load the bitmap from its path
1473
- bmp = BitmapFactory.decodeFile(filePath, options);
1474
- } catch (OutOfMemoryError exception) {
1475
- exception.printStackTrace();
1476
- }
1477
- try {
1478
- scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888);
1479
- } catch (OutOfMemoryError exception) {
1480
- exception.printStackTrace();
1481
- }
1482
- float ratioX = actualWidth / (float) options.outWidth;
1483
- float ratioY = actualHeight / (float) options.outHeight;
1484
- float middleX = actualWidth / 2.0f;
1485
- float middleY = actualHeight / 2.0f;
1486
- Matrix scaleMatrix = new Matrix();
1487
- scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
1488
- Canvas canvas = new Canvas(scaledBitmap);
1489
- canvas.setMatrix(scaleMatrix);
1490
- canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));
1491
- //check the rotation of the image and display it properly
1492
- ExifInterface exif;
1493
- try {
1494
- exif = new ExifInterface(filePath);
1495
- int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
1496
- Log.d("EXIF", "Exif: " + orientation);
1497
- Matrix matrix = new Matrix();
1498
- if (orientation == 6) {
1499
- matrix.postRotate(90);
1500
- Log.d("EXIF", "Exif: " + orientation);
1501
- } else if (orientation == 3) {
1502
- matrix.postRotate(180);
1503
- Log.d("EXIF", "Exif: " + orientation);
1504
- } else if (orientation == 8) {
1505
- matrix.postRotate(270);
1506
- Log.d("EXIF", "Exif: " + orientation);
1507
- }
1508
- scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
1509
- } catch (IOException e) {
1510
- e.printStackTrace();
1511
- }
1512
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
1513
- try {
1514
- if (imgSrcType.equals("compress")) {
1515
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1516
- if (!destinationPath.equalsIgnoreCase("")) {
1517
- compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + destinationPath;
1518
- } else {
1519
- compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images";
1520
- }
1521
- compressedImageName = compressedImagePathStr + "/" + fileNameToSend + "_" + timeStamp + ".jpg";
1522
- File fileSavedPath = new File(compressedImagePathStr);
1523
- if (!fileSavedPath.exists()) {
1524
- fileSavedPath.mkdirs();
1525
- }
1526
- FileOutputStream out = new FileOutputStream(compressedImageName);
1527
- if (scaledBitmap != null) {
1528
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, out);
1529
- }
1530
- } else {
1531
- if (scaledBitmap != null) {
1532
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, baos);
1533
- }
1534
- }
1535
- String encodedImage;
1536
- byte[] byteArray;
1537
- try {
1538
- byteArray = baos.toByteArray();
1539
- encodedImage = Base64.encodeToString(byteArray, Base64.NO_WRAP);
1540
- if (imgSrcType.equals("camera")) {
1541
- File file = new File(imageSourcePath);
1542
- if (file.exists()) {
1543
- file.delete();
1544
- }
1545
- attachmentDestPath = "";
1546
- callbackContext.success(encodedImage);
1547
- } else if (imgSrcType.equals("gallery")) {
1548
- attachmentDestPath = "";
1549
- callbackContext.success(encodedImage);
1550
- } else if (imgSrcType.equals("compress")) {
1551
- try {
1552
- if (!destinationPath.equalsIgnoreCase("")) {
1553
- File file = new File(imageSourcePath);
1554
- if (file.exists()) {
1555
- file.delete();
1556
- }
1557
- }
1558
- JSONObject fileProperities;
1559
- String imgFilePath, fileName, fileExtension;
1560
- imgFilePath = compressedImageName.substring(0, compressedImageName.lastIndexOf("/"));
1561
- String[] fileName1 = compressedImageName.split("/");
1562
- fileName = fileName1[fileName1.length - 1];
1563
- File file = new File(compressedImageName);
1564
- long fileSize = file.length();
1565
- fileExtension = "." + compressedImageName.substring(compressedImageName.lastIndexOf(".") + 1).toLowerCase();
1566
- fileProperities = new JSONObject();
1567
- fileProperities.put("filePath", imgFilePath);
1568
- fileProperities.put("fileName", fileName);
1569
- fileProperities.put("fileSize", fileSize);
1570
- fileProperities.put("fileExtension", fileExtension);
1571
- fileProperities.put("thumbnail", getFileThumbnail(imgFilePath + "/" + fileName, fileExtension));
1572
- attachmentDestPath = "";
1573
- callback.success(fileProperities);
1574
- } catch (Exception e) {
1575
- attachmentDestPath = "";
1576
- callback.error(e.getMessage());
1577
- }
1578
- }
1579
- } catch (Exception e) {
1580
- attachmentDestPath = "";
1581
- callbackContext.error(e.getMessage());
1582
- }
1583
- } catch (Exception e) {
1584
- e.printStackTrace();
1585
- }
1586
- }
1587
-
1588
1430
  public String getBase64String(String imageSourcePath) {
1589
1431
  String resultString = "";
1590
1432
  try {
@@ -1611,7 +1453,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1611
1453
  pluginResult.setKeepCallback(true);
1612
1454
  callbackContext.sendPluginResult(pluginResult);
1613
1455
  } catch (Exception e) {
1614
- callbackContext.error(e.getMessage());
1456
+ callbackContext.error("unable to choose file, exception is : "+e.getMessage());
1615
1457
  }
1616
1458
  }
1617
1459
 
@@ -1644,7 +1486,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1644
1486
  r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
1645
1487
  callbackContext.success(r);
1646
1488
  } catch (Exception e) {
1647
- callbackContext.error(e.getMessage());
1489
+ callbackContext.error("unable to get appVersion, exception is : "+e.getMessage());
1648
1490
  }
1649
1491
  }
1650
1492
 
@@ -1677,7 +1519,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1677
1519
  }
1678
1520
  callbackContext.success(currentOrientation);
1679
1521
  } catch (Exception e) {
1680
- callbackContext.success(e.getMessage());
1522
+ callbackContext.success("rotateScreen failed, exception is : "+e.getMessage());
1681
1523
  }
1682
1524
  }
1683
1525
 
@@ -1702,7 +1544,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1702
1544
  r.put("applicationName", getApplicationName(cordova.getActivity()));
1703
1545
  callbackContext.success(r);
1704
1546
  } catch (Exception e) {
1705
- callbackContext.error(e.getMessage());
1547
+ callbackContext.error("unable to get deviceInfo, exception is : "+e.getMessage());
1706
1548
  }
1707
1549
  }
1708
1550
 
@@ -1964,13 +1806,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1964
1806
  }
1965
1807
  }
1966
1808
  } catch (Exception e) {
1967
- callback.error(e.getMessage());
1809
+ callback.error("onActivityResult failed, exception is : "+e.getMessage());
1968
1810
  }
1969
1811
  } else {
1970
- callback.error("Selected file path is null");
1812
+ callback.error("onActivityResult: Selected file path is null");
1971
1813
  }
1972
1814
  } catch (Exception e) {
1973
- callback.error(e.getMessage());
1815
+ callback.error("onActivityResult failed, exception is : "+e.getMessage());
1974
1816
  }
1975
1817
  } else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
1976
1818
  if (resultCode == RESULT_OK) {
@@ -2212,7 +2054,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2212
2054
  callback.error("Error occurred in opening outputStream");
2213
2055
  }
2214
2056
  } catch (Exception e) {
2215
- callback.error("Exception occurred " + e.getMessage());
2057
+ callback.error("copyFileFromUri failed, exception is : "+e.getMessage());
2216
2058
  }
2217
2059
  return outPutFilePath;
2218
2060
  }
@@ -2266,7 +2108,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2266
2108
  .checkLocationSettings(mGoogleApiClient1, builder.build());
2267
2109
  result.setResultCallback(this);
2268
2110
  } catch (Exception e) {
2269
- callbackContext.error(e.getMessage());
2111
+ callbackContext.error("EnableGPSAutomatically failed, exception is : "+e.getMessage());
2270
2112
  }
2271
2113
  }
2272
2114
 
@@ -2277,7 +2119,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2277
2119
  startLocationUpdates1();
2278
2120
  }
2279
2121
  } catch (Exception e) {
2280
- System.out.println(e.getMessage());
2122
+ System.out.println("GoogleApiClient failed, exception is : "+e.getMessage());
2281
2123
  }
2282
2124
  }
2283
2125
 
@@ -2309,7 +2151,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2309
2151
  break;
2310
2152
  }
2311
2153
  } catch (Exception e) {
2312
- System.out.println(e.getMessage());
2154
+ System.out.println("LocationSettingsResult failed, exception is : "+e.getMessage());
2313
2155
  }
2314
2156
  }
2315
2157
 
@@ -2323,7 +2165,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2323
2165
  callback.success(mCurrentLocation1.getLatitude() + "," + mCurrentLocation1.getLongitude());
2324
2166
  }
2325
2167
  } catch (Exception e) {
2326
- callback.error(e.getMessage());
2168
+ callback.error("onLocationChanged failed, exception is : "+e.getMessage());
2327
2169
  }
2328
2170
  }
2329
2171
 
@@ -2379,7 +2221,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2379
2221
  output.write(data, 0, count);
2380
2222
  }
2381
2223
  } catch (Exception e) {
2382
- downloadFileCallback.error("Failure..." + e.getMessage());
2224
+ downloadFileCallback.error("DownloadTask failed for url"+sUrl[0]+" , exception is : "+e.getMessage());
2383
2225
  }
2384
2226
  if (sUrl[2].equalsIgnoreCase("true")) {
2385
2227
  return sUrl[1];
@@ -2405,7 +2247,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2405
2247
  downloadFileCallback.success("");
2406
2248
  }
2407
2249
  } catch (Exception e) {
2408
- downloadFileCallback.error(e.getMessage());
2250
+ downloadFileCallback.error("copyAttachmentFile failed, exception is : "+e.getMessage());
2409
2251
  }
2410
2252
  }
2411
2253
  }
@@ -2502,7 +2344,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2502
2344
  else
2503
2345
  callbackContext.error("Bad zip file");
2504
2346
  } catch (Exception e) {
2505
- String errorMessage = e.getMessage();
2347
+ String errorMessage = "unzipSync failed, exception is : "+e.getMessage();
2506
2348
  callbackContext.error(errorMessage);
2507
2349
  } finally {
2508
2350
  if (inputStream != null) {
@@ -5,6 +5,7 @@ import static com.selfservit.util.mInterface.pathComponent;
5
5
  import android.annotation.TargetApi;
6
6
  import android.app.Activity;
7
7
  import android.content.Context;
8
+ import android.content.SharedPreferences;
8
9
  import android.database.Cursor;
9
10
  import android.graphics.Bitmap;
10
11
  import android.graphics.BitmapFactory;
@@ -85,6 +86,8 @@ public class mInterfaceUtil {
85
86
  public static String deviceID = "";
86
87
  public static String timerInd = "";
87
88
 
89
+ private static final String PREFS_NAME = "app_prefs";
90
+ private static final String KEY_FIRST_LAUNCH = "first_launch";
88
91
  public static String decrypt(String encryptedText) {
89
92
  String decryptedText = "";
90
93
  try {
@@ -157,7 +160,7 @@ public class mInterfaceUtil {
157
160
  output.write(data, 0, count);
158
161
  }
159
162
  } catch (Exception e) {
160
- callbackContext.error("Failure" + e.getMessage());
163
+ callbackContext.error("DownloadChatAttachment failed, Exception is : " + e.getMessage());
161
164
  }
162
165
  if (thumbnailInd.equalsIgnoreCase("true")) {
163
166
  return filePath;
@@ -182,7 +185,7 @@ public class mInterfaceUtil {
182
185
  String thumbnail = getFileThumbnail(filePath, extension, context);
183
186
  callbackContext.success(thumbnail);
184
187
  } else {
185
- callbackContext.error("Failure");
188
+ callbackContext.error("DownloadChatAttachment: Failure");
186
189
  }
187
190
  } else {
188
191
  callbackContext.success("success");
@@ -209,7 +212,7 @@ public class mInterfaceUtil {
209
212
  byte[] cipherText = android.util.Base64.encode(cipher.doFinal(plainText.getBytes(StandardCharsets.UTF_8)), 0);
210
213
  encryptedText = new String(cipherText);
211
214
  } catch (Exception E) {
212
- System.out.println("decrypt Exception : " + E.getMessage());
215
+ System.out.println("Failed to decrypt: Exception : " + E.getMessage());
213
216
  }
214
217
  return encryptedText;
215
218
  }
@@ -299,10 +302,10 @@ public class mInterfaceUtil {
299
302
  if (filePath.exists()) {
300
303
  filePath.delete();
301
304
  } else {
302
- callbackContext.error("No file there & File not deleted for " + str);
305
+ callbackContext.error("No file available & File not deleted for " + str);
303
306
  }
304
307
  } catch (Exception e) {
305
- callbackContext.error(e.getMessage());
308
+ callbackContext.error("deleteMultipleFiles failed: Exception is : "+e.getMessage());
306
309
  }
307
310
  }
308
311
 
@@ -349,7 +352,7 @@ public class mInterfaceUtil {
349
352
  }
350
353
  callbackContext.success("success");
351
354
  } catch (Exception e) {
352
- callbackContext.error(e.getMessage());
355
+ callbackContext.error("copyConfigFile failed, Exception is" + e.getMessage());
353
356
  }
354
357
  }
355
358
 
@@ -395,7 +398,7 @@ public class mInterfaceUtil {
395
398
  }
396
399
  callbackContext.success("success");
397
400
  } catch (Exception e) {
398
- callbackContext.error(e.getMessage());
401
+ callbackContext.error("copyFile failed exception is : "+e.getMessage());
399
402
  }
400
403
  }
401
404
 
@@ -460,7 +463,7 @@ public class mInterfaceUtil {
460
463
  deleteFilesFromDirectory();
461
464
  callbackContext.success("success");
462
465
  } catch (Exception e) {
463
- callbackContext.error(e.getMessage());
466
+ callbackContext.error("copyAttachmentFile failed, exception is : "+e.getMessage());
464
467
  }
465
468
  }
466
469
 
@@ -508,7 +511,7 @@ public class mInterfaceUtil {
508
511
  }
509
512
  callbackContext.success("success");
510
513
  } catch (Exception e) {
511
- callbackContext.error(e.getMessage());
514
+ callbackContext.error("Move File failed, exception is : "+e.getMessage());
512
515
  }
513
516
  }
514
517
 
@@ -656,7 +659,7 @@ public class mInterfaceUtil {
656
659
  }
657
660
  } catch (Exception e) {
658
661
  callbackContext.error(e.getMessage());
659
- System.out.println("out exception : " + e.getMessage());
662
+ System.out.println("Queue processor failed, exception is : "+ e.getMessage());
660
663
  }
661
664
  }
662
665
 
@@ -1144,10 +1147,10 @@ public class mInterfaceUtil {
1144
1147
  String content = new Scanner(filePath).useDelimiter("\\A").next();
1145
1148
  callbackContext.success(content);
1146
1149
  } else {
1147
- callbackContext.error("There is no file at the given path..");
1150
+ callbackContext.error("There is no file at the given path. Path: " + filePath);
1148
1151
  }
1149
1152
  } catch (Exception e) {
1150
- callbackContext.error(e.getMessage());
1153
+ callbackContext.error("unable to readFile, Exception is: "+e.getMessage());
1151
1154
  }
1152
1155
  }
1153
1156
 
@@ -1159,10 +1162,10 @@ public class mInterfaceUtil {
1159
1162
  filePath.delete();
1160
1163
  callbackContext.success();
1161
1164
  } else {
1162
- callbackContext.error("File not deleted..");
1165
+ callbackContext.error("File not deleted, Path: "+baseDirectory + "/" + args.getJSONObject(0).optString("filePath"));
1163
1166
  }
1164
1167
  } catch (Exception e) {
1165
- callbackContext.error(e.getMessage());
1168
+ callbackContext.error("delete file failed, exception is : "+e.getMessage());
1166
1169
  }
1167
1170
  }
1168
1171
 
@@ -1184,7 +1187,11 @@ public class mInterfaceUtil {
1184
1187
  fileWriterObj.close();
1185
1188
  callbackContext.success();
1186
1189
  } catch (Exception e) {
1187
- callbackContext.error(e.getMessage());
1190
+ try {
1191
+ callbackContext.error("create File failed for path:"+ args.getJSONObject(0).optString("filePath") +" , exception is : "+e.getMessage());
1192
+ } catch (JSONException ex) {
1193
+ e.printStackTrace();
1194
+ }
1188
1195
  }
1189
1196
  }
1190
1197
 
@@ -1195,7 +1202,11 @@ public class mInterfaceUtil {
1195
1202
  boolean sss = filePath.exists();
1196
1203
  callbackContext.success(sss ? "true" : "false");
1197
1204
  } catch (Exception e) {
1198
- callbackContext.error(e.getMessage());
1205
+ try {
1206
+ callbackContext.error("validate file failed for path:"+baseDirectory + "/" + args.getJSONObject(0).optString("filePath")+" , exception is : "+e.getMessage());
1207
+ } catch (JSONException ex) {
1208
+ e.printStackTrace();
1209
+ }
1199
1210
  }
1200
1211
  }
1201
1212
 
@@ -1210,7 +1221,11 @@ public class mInterfaceUtil {
1210
1221
  }
1211
1222
  callbackContext.success();
1212
1223
  } catch (Exception e) {
1213
- callbackContext.error(e.getMessage());
1224
+ try {
1225
+ callbackContext.error("create directory failed for " + args.getJSONObject(0).optString("filePath") +", exception is : "+e.getMessage());
1226
+ } catch (JSONException ex) {
1227
+ e.printStackTrace();
1228
+ }
1214
1229
  }
1215
1230
  }
1216
1231
 
@@ -1220,19 +1235,23 @@ public class mInterfaceUtil {
1220
1235
  try {
1221
1236
  String fileName = args.getJSONObject(0).optString("filePath");
1222
1237
  if (fileName.equals("")) {
1223
- callbackContext.error("Given directory path is empty.");
1238
+ callbackContext.error("deleteDirectory: Given directory path is empty. path: "+args.getJSONObject(0).optString("filePath"));
1224
1239
  } else {
1225
1240
  File dir = new File(rootDirectory + "/" + fileName);
1226
1241
  if (dir.exists()) {
1227
1242
  deleteRecursive(dir);
1228
1243
  callbackContext.success();
1229
1244
  } else {
1230
- callbackContext.error("File does not exists");
1245
+ callbackContext.error("deleteDirectory: File does not exists in "+args.getJSONObject(0).optString("filePath"));
1231
1246
  }
1232
1247
 
1233
1248
  }
1234
1249
  } catch (Exception e) {
1235
- callbackContext.error(e.getMessage());
1250
+ try {
1251
+ callbackContext.error("delete directory failed for "+args.getJSONObject(0).optString("filePath")+", exception is : "+e.getMessage());
1252
+ } catch (JSONException ex) {
1253
+ throw new RuntimeException(ex);
1254
+ }
1236
1255
  }
1237
1256
  }
1238
1257
 
@@ -1247,7 +1266,7 @@ public class mInterfaceUtil {
1247
1266
 
1248
1267
  fileOrDirectory.delete();
1249
1268
  } catch (Exception e) {
1250
- throw new RuntimeException(e);
1269
+ e.printStackTrace();
1251
1270
  }
1252
1271
  }
1253
1272
 
@@ -1289,7 +1308,7 @@ public class mInterfaceUtil {
1289
1308
  callbackContext.success();
1290
1309
  } catch (Exception e) {
1291
1310
  e.printStackTrace();
1292
- callbackContext.error(e.getMessage());
1311
+ callbackContext.error("unzip failed, exception is : "+e.getMessage());
1293
1312
  }
1294
1313
  }
1295
1314
 
@@ -1315,7 +1334,11 @@ public class mInterfaceUtil {
1315
1334
  callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
1316
1335
  }
1317
1336
  } catch (Exception e) {
1318
- callbackContext.error(e.getMessage());
1337
+ try {
1338
+ callbackContext.error("getSubDirectoryList failed for "+args.getJSONObject(0).optString("filePath")+", exception is : "+e.getMessage());
1339
+ } catch (JSONException ex) {
1340
+ e.printStackTrace();
1341
+ }
1319
1342
  }
1320
1343
  }
1321
1344
 
@@ -1341,7 +1364,11 @@ public class mInterfaceUtil {
1341
1364
  callbackContext.success(fileNames.length() > 0 ? fileNames.substring(0, fileNames.length() - 1) : "");
1342
1365
  }
1343
1366
  } catch (Exception e) {
1344
- callbackContext.error(e.getMessage());
1367
+ try {
1368
+ callbackContext.error("getFileList failed for "+args.getJSONObject(0).optString("filePath")+", exception is : "+e.getMessage());
1369
+ } catch (JSONException ex) {
1370
+ e.printStackTrace();
1371
+ }
1345
1372
  }
1346
1373
  }
1347
1374
 
@@ -1381,7 +1408,7 @@ public class mInterfaceUtil {
1381
1408
  }
1382
1409
  } catch (Exception e) {
1383
1410
  System.out.println(e.getMessage());
1384
- callbackContext.error(e.getMessage());
1411
+ callbackContext.error("getAppStateInfo failed, exception is : "+e.getMessage());
1385
1412
  }
1386
1413
  }
1387
1414
 
@@ -1700,6 +1727,8 @@ public class mInterfaceUtil {
1700
1727
  return true;
1701
1728
  }
1702
1729
 
1730
+
1731
+
1703
1732
  public static boolean isConnected(Context applicationContext) {
1704
1733
  try {
1705
1734
  ConnectivityManager online = (ConnectivityManager) applicationContext.getSystemService(Context.CONNECTIVITY_SERVICE);
@@ -1710,4 +1739,66 @@ public class mInterfaceUtil {
1710
1739
  }
1711
1740
  return false;
1712
1741
  }
1742
+
1743
+ public static void appCleanUp(CallbackContext callbackContext, Context applicationContext){
1744
+ try {
1745
+ if (isFirstLaunch(applicationContext)) {
1746
+ performCleanup(applicationContext);
1747
+ setFirstLaunch(applicationContext, false);
1748
+ }
1749
+ callbackContext.success("Success");
1750
+ } catch (Exception e) {
1751
+ e.printStackTrace();
1752
+ callbackContext.error("AppCleanUp Failed, Exception is" + e.getMessage());
1753
+ }
1754
+ }
1755
+
1756
+ private static void performCleanup(Context context) {
1757
+ // Delete files in the internal storage directory
1758
+ File internalFilesDir = context.getFilesDir();
1759
+ deleteDirectory(internalFilesDir);
1760
+ // Delete files in the cache directory
1761
+ File cacheDir = context.getCacheDir();
1762
+ deleteDirectory(cacheDir);
1763
+ // Delete files in the external storage directory
1764
+ File externalFilesDir = context.getExternalFilesDir(null);
1765
+ if (externalFilesDir != null) {
1766
+ deleteDirectory(externalFilesDir);
1767
+ }
1768
+ // Delete files in the external cache directory
1769
+ File externalCacheDir = context.getExternalCacheDir();
1770
+ if (externalCacheDir != null) {
1771
+ deleteDirectory(externalCacheDir);
1772
+ }
1773
+
1774
+ }
1775
+
1776
+ public static boolean isFirstLaunch(Context context) {
1777
+ SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
1778
+ return prefs.getBoolean(KEY_FIRST_LAUNCH, true);
1779
+ }
1780
+ public static void setFirstLaunch(Context context, boolean value) {
1781
+ SharedPreferences prefs = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
1782
+ SharedPreferences.Editor editor = prefs.edit();
1783
+ editor.putBoolean(KEY_FIRST_LAUNCH, value);
1784
+ editor.apply();
1785
+ }
1786
+ private static void deleteDirectory(File dir) {
1787
+ if (dir != null && dir.isDirectory()) {
1788
+ File[] files = dir.listFiles();
1789
+ if (files != null) {
1790
+ for (File file : files) {
1791
+ if (file.isDirectory()) {
1792
+ deleteDirectory(file);
1793
+ } else {
1794
+ boolean deleted = file.delete();
1795
+ if (!deleted) {
1796
+ Log.e("FileUtils", "Failed to delete file: " + file.getAbsolutePath());
1797
+ }
1798
+ }
1799
+ }
1800
+ }
1801
+ }
1802
+ }
1803
+
1713
1804
  }