cordova-plugin-mserviceinterface-2.0 1.0.67 → 1.0.69
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/plugin.xml +1 -1
- package/src/android/mInterface.java +84 -38
- package/src/android/mInterfaceService.java +38 -63
- package/src/android/mInterfaceUtil.java +114 -65
- package/src/ios/mInterface.h +1 -0
- package/src/ios/mInterface.m +468 -240
package/package.json
CHANGED
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.
|
|
5
|
+
version="1.0.69">
|
|
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>
|
|
@@ -21,6 +21,7 @@ import android.database.Cursor;
|
|
|
21
21
|
import android.graphics.Bitmap;
|
|
22
22
|
import android.graphics.BitmapFactory;
|
|
23
23
|
import android.graphics.Canvas;
|
|
24
|
+
import android.graphics.Color;
|
|
24
25
|
import android.graphics.Matrix;
|
|
25
26
|
import android.graphics.Paint;
|
|
26
27
|
import android.location.Location;
|
|
@@ -82,6 +83,7 @@ import java.io.ByteArrayOutputStream;
|
|
|
82
83
|
import java.io.File;
|
|
83
84
|
import java.io.FileInputStream;
|
|
84
85
|
import java.io.FileOutputStream;
|
|
86
|
+
import java.io.FileReader;
|
|
85
87
|
import java.io.IOException;
|
|
86
88
|
import java.io.InputStream;
|
|
87
89
|
import java.io.InputStreamReader;
|
|
@@ -184,7 +186,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
184
186
|
Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_SHORT).show();
|
|
185
187
|
}
|
|
186
188
|
} catch (Exception exception) {
|
|
187
|
-
callbackContext.error("showToastWithOptions: "+ exception.getMessage());
|
|
189
|
+
callbackContext.error("showToastWithOptions: " + exception.getMessage());
|
|
188
190
|
}
|
|
189
191
|
} else if (action.equals("CheckLocationAccuracy")) {
|
|
190
192
|
int locationInt;
|
|
@@ -579,7 +581,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
579
581
|
try {
|
|
580
582
|
new mInterfaceUtil().readFile(args, callbackContext);
|
|
581
583
|
} catch (Exception e) {
|
|
582
|
-
callbackContext.error("ReadFile failed, exception is : "+e.getMessage());
|
|
584
|
+
callbackContext.error("ReadFile failed, exception is : " + e.getMessage());
|
|
583
585
|
}
|
|
584
586
|
return true;
|
|
585
587
|
} else if (action.equals("DeleteFile")) {
|
|
@@ -713,7 +715,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
713
715
|
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + cordova.getActivity().getApplicationContext().getPackageName())));
|
|
714
716
|
callbackContext.success("success");
|
|
715
717
|
} catch (Exception e) {
|
|
716
|
-
callbackContext.error("UpdateNew failed, exception is : "+e.getMessage());
|
|
718
|
+
callbackContext.error("UpdateNew failed, exception is : " + e.getMessage());
|
|
717
719
|
}
|
|
718
720
|
} else if (action.equals("OpenFileWithViewer")) {
|
|
719
721
|
try {
|
|
@@ -733,7 +735,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
733
735
|
cordova.getActivity().startActivity(intent);
|
|
734
736
|
callbackContext.success();
|
|
735
737
|
} catch (Exception e) {
|
|
736
|
-
callbackContext.error("OpenFileWithViewer failed, exception is : "+e.getMessage());
|
|
738
|
+
callbackContext.error("OpenFileWithViewer failed, exception is : " + e.getMessage());
|
|
737
739
|
}
|
|
738
740
|
} else if (action.equals("CaptureImageFromCamera")) {
|
|
739
741
|
try {
|
|
@@ -744,7 +746,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
744
746
|
captureImage(callbackContext);
|
|
745
747
|
return true;
|
|
746
748
|
} catch (Exception e) {
|
|
747
|
-
callbackContext.error("CaptureImageFromCamera failed, exception is : "+e.getMessage());
|
|
749
|
+
callbackContext.error("CaptureImageFromCamera failed, exception is : " + e.getMessage());
|
|
748
750
|
}
|
|
749
751
|
} else if (action.equals("PickImageFromGallery")) {
|
|
750
752
|
try {
|
|
@@ -755,7 +757,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
755
757
|
pickImageFromGallery(callbackContext);
|
|
756
758
|
return true;
|
|
757
759
|
} catch (Exception e) {
|
|
758
|
-
callbackContext.error("PickImageFromGallery failed, exception is : "+e.getMessage());
|
|
760
|
+
callbackContext.error("PickImageFromGallery failed, exception is : " + e.getMessage());
|
|
759
761
|
}
|
|
760
762
|
} else if (action.equals("CaptureFromCamera")) {
|
|
761
763
|
try {
|
|
@@ -784,7 +786,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
784
786
|
final DownloadTask downloadTask = new DownloadTask(cordova.getActivity(), callback);
|
|
785
787
|
downloadTask.execute(args.optJSONObject(0).optString("url"), args.optJSONObject(0).optString("filePath"), args.optJSONObject(0).optString("thumbnailInd"));
|
|
786
788
|
} catch (Exception e) {
|
|
787
|
-
callbackContext.error("DownloadFile failed for "+args.optJSONObject(0).optString("url")+", exception is : "+e.getMessage());
|
|
789
|
+
callbackContext.error("DownloadFile failed for " + args.optJSONObject(0).optString("url") + ", exception is : " + e.getMessage());
|
|
788
790
|
}
|
|
789
791
|
return true;
|
|
790
792
|
} else if ("QueueProcessor".equals(action)) {
|
|
@@ -795,14 +797,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
795
797
|
scanQRCode(callbackContext);
|
|
796
798
|
return true;
|
|
797
799
|
} catch (Exception e) {
|
|
798
|
-
callbackContext.error("ScanQRCode failed, exception is : "+e.getMessage());
|
|
800
|
+
callbackContext.error("ScanQRCode failed, exception is : " + e.getMessage());
|
|
799
801
|
}
|
|
800
802
|
} else if (action.equals("ScanBarCode")) {
|
|
801
803
|
try {
|
|
802
804
|
scanBarCode(callbackContext);
|
|
803
805
|
return true;
|
|
804
806
|
} catch (Exception e) {
|
|
805
|
-
callbackContext.error("ScanBarCode failed, exception is : "+e.getMessage());
|
|
807
|
+
callbackContext.error("ScanBarCode failed, exception is : " + e.getMessage());
|
|
806
808
|
}
|
|
807
809
|
} else if (action.equals("GetSubDirectoryList")) {
|
|
808
810
|
new mInterfaceUtil().getSubDirectoryList(args, callbackContext);
|
|
@@ -821,7 +823,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
821
823
|
callbackContext.success("");
|
|
822
824
|
}
|
|
823
825
|
} catch (Exception e) {
|
|
824
|
-
callbackContext.error("GetAppStateInfo failed, exception is : "+e.getMessage());
|
|
826
|
+
callbackContext.error("GetAppStateInfo failed, exception is : " + e.getMessage());
|
|
825
827
|
}
|
|
826
828
|
return true;
|
|
827
829
|
} else if (action.equals("UpdateAppInfo")) {
|
|
@@ -833,7 +835,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
833
835
|
callbackContext.error("failed to update app info");
|
|
834
836
|
}
|
|
835
837
|
} catch (Exception e) {
|
|
836
|
-
callbackContext.error("UpdateAppInfo failed, exception is : "+e.getMessage());
|
|
838
|
+
callbackContext.error("UpdateAppInfo failed, exception is : " + e.getMessage());
|
|
837
839
|
}
|
|
838
840
|
return true;
|
|
839
841
|
} else if (action.equals("MoveFile")) {
|
|
@@ -876,7 +878,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
876
878
|
}
|
|
877
879
|
} catch (JSONException e) {
|
|
878
880
|
e.printStackTrace();
|
|
879
|
-
result = new PluginResult(PluginResult.Status.ERROR, "OpenSms failed, exception is : "+e.getMessage());
|
|
881
|
+
result = new PluginResult(PluginResult.Status.ERROR, "OpenSms failed, exception is : " + e.getMessage());
|
|
880
882
|
callback.sendPluginResult(result);
|
|
881
883
|
}
|
|
882
884
|
return true;
|
|
@@ -947,7 +949,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
947
949
|
}
|
|
948
950
|
} catch (Exception e) {
|
|
949
951
|
e.printStackTrace();
|
|
950
|
-
result = new PluginResult(PluginResult.Status.ERROR, "OpenEmail failed, exception is : "+e.getMessage());
|
|
952
|
+
result = new PluginResult(PluginResult.Status.ERROR, "OpenEmail failed, exception is : " + e.getMessage());
|
|
951
953
|
callback.sendPluginResult(result);
|
|
952
954
|
}
|
|
953
955
|
|
|
@@ -961,17 +963,62 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
961
963
|
callbackContext.success("success");
|
|
962
964
|
} catch (Exception e) {
|
|
963
965
|
e.printStackTrace();
|
|
964
|
-
result = new PluginResult(PluginResult.Status.ERROR, "copyAttachmentFile failed, exception is : "+e.getMessage());
|
|
966
|
+
result = new PluginResult(PluginResult.Status.ERROR, "copyAttachmentFile failed, exception is : " + e.getMessage());
|
|
965
967
|
callback.sendPluginResult(result);
|
|
966
968
|
}
|
|
967
969
|
|
|
970
|
+
} else if (action.equals("getMyAccountsData")) {
|
|
971
|
+
try {
|
|
972
|
+
String folderPath = mInterfaceUtil.rootDirectory + "/" + args.getJSONObject(0).optString("folderPath");
|
|
973
|
+
ArrayList<JSONObject> dataArray = getJsonDataFromFiles(folderPath);
|
|
974
|
+
JSONArray jsonResult = new JSONArray(dataArray);
|
|
975
|
+
callbackContext.success(jsonResult.toString());
|
|
976
|
+
} catch (Exception e) {
|
|
977
|
+
e.printStackTrace();
|
|
978
|
+
PluginResult result = new PluginResult(PluginResult.Status.ERROR, "getMyAccountsData failed, exception is : " + e.getMessage());
|
|
979
|
+
callback.sendPluginResult(result);
|
|
980
|
+
}
|
|
981
|
+
} else if (action.equals("KillBackgroundExecutions")) {
|
|
982
|
+
callbackContext.success("success");
|
|
983
|
+
return true;
|
|
968
984
|
}
|
|
969
985
|
} catch (JSONException e) {
|
|
970
|
-
System.out.println(" unable to proccess plugin method, exception is : "+e.getMessage());
|
|
986
|
+
System.out.println(" unable to proccess plugin method, exception is : " + e.getMessage());
|
|
971
987
|
}
|
|
972
988
|
return true;
|
|
973
989
|
}
|
|
974
990
|
|
|
991
|
+
public static ArrayList<JSONObject> getJsonDataFromFiles(String folderPath) {
|
|
992
|
+
ArrayList<JSONObject> dataArray = new ArrayList<>();
|
|
993
|
+
try {
|
|
994
|
+
File folder = new File(folderPath);
|
|
995
|
+
if (folder.exists() && folder.isDirectory()) {
|
|
996
|
+
File[] files = folder.listFiles();
|
|
997
|
+
|
|
998
|
+
if (files != null) {
|
|
999
|
+
for (File file : files) {
|
|
1000
|
+
if (file.isFile() && file.getName().endsWith(".json")) {
|
|
1001
|
+
StringBuilder jsonData = new StringBuilder();
|
|
1002
|
+
try (FileReader reader = new FileReader(file)) {
|
|
1003
|
+
int character;
|
|
1004
|
+
while ((character = reader.read()) != -1) {
|
|
1005
|
+
jsonData.append((char) character);
|
|
1006
|
+
}
|
|
1007
|
+
JSONObject jsonObject = new JSONObject(mInterfaceUtil.decrypt(jsonData.toString()));
|
|
1008
|
+
dataArray.add(jsonObject);
|
|
1009
|
+
} catch (IOException e) {
|
|
1010
|
+
e.printStackTrace();
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
}
|
|
1015
|
+
}
|
|
1016
|
+
} catch (Exception e) {
|
|
1017
|
+
e.printStackTrace();
|
|
1018
|
+
}
|
|
1019
|
+
return dataArray;
|
|
1020
|
+
}
|
|
1021
|
+
|
|
975
1022
|
private boolean validateMobileNumber(String mobileNo) {
|
|
976
1023
|
String regex;
|
|
977
1024
|
boolean result = false;
|
|
@@ -1047,7 +1094,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1047
1094
|
pluginResult.setKeepCallback(true);
|
|
1048
1095
|
callbackContext.sendPluginResult(pluginResult);
|
|
1049
1096
|
} catch (Exception e) {
|
|
1050
|
-
callbackContext.error("scanQRCode failed, exception is : "+e.getMessage());
|
|
1097
|
+
callbackContext.error("scanQRCode failed, exception is : " + e.getMessage());
|
|
1051
1098
|
}
|
|
1052
1099
|
}
|
|
1053
1100
|
|
|
@@ -1067,7 +1114,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1067
1114
|
pluginResult.setKeepCallback(true);
|
|
1068
1115
|
callbackContext.sendPluginResult(pluginResult);
|
|
1069
1116
|
} catch (Exception e) {
|
|
1070
|
-
callbackContext.error("scanBarCode failed, exception is : "+e.getMessage());
|
|
1117
|
+
callbackContext.error("scanBarCode failed, exception is : " + e.getMessage());
|
|
1071
1118
|
}
|
|
1072
1119
|
}
|
|
1073
1120
|
|
|
@@ -1075,7 +1122,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1075
1122
|
try {
|
|
1076
1123
|
callbackContext.success("file://" + mInterfaceUtil.rootDirectory + "/");
|
|
1077
1124
|
} catch (Exception e) {
|
|
1078
|
-
callbackContext.error("getStorageRoot failed, exception is : "+e.getMessage());
|
|
1125
|
+
callbackContext.error("getStorageRoot failed, exception is : " + e.getMessage());
|
|
1079
1126
|
}
|
|
1080
1127
|
}
|
|
1081
1128
|
|
|
@@ -1171,7 +1218,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1171
1218
|
callback.success("success");
|
|
1172
1219
|
}
|
|
1173
1220
|
} catch (Exception e) {
|
|
1174
|
-
callback.error("getPermissions failed, exception is : "+e.getMessage());
|
|
1221
|
+
callback.error("getPermissions failed, exception is : " + e.getMessage());
|
|
1175
1222
|
}
|
|
1176
1223
|
}
|
|
1177
1224
|
|
|
@@ -1247,7 +1294,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1247
1294
|
pluginResult.setKeepCallback(true);
|
|
1248
1295
|
callbackContext.sendPluginResult(pluginResult);
|
|
1249
1296
|
} catch (Exception e) {
|
|
1250
|
-
callbackContext.error("pickImageFromGallery failed, exception is : "+e.getMessage());
|
|
1297
|
+
callbackContext.error("pickImageFromGallery failed, exception is : " + e.getMessage());
|
|
1251
1298
|
}
|
|
1252
1299
|
}
|
|
1253
1300
|
|
|
@@ -1413,12 +1460,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1413
1460
|
callback.success(fileProperities);
|
|
1414
1461
|
} catch (Exception e) {
|
|
1415
1462
|
attachmentDestPath = "";
|
|
1416
|
-
callback.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
|
|
1463
|
+
callback.error("convertImageTo64BaseString failed, exception is : " + e.getMessage());
|
|
1417
1464
|
}
|
|
1418
1465
|
}
|
|
1419
1466
|
} catch (Exception e) {
|
|
1420
1467
|
attachmentDestPath = "";
|
|
1421
|
-
callbackContext.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
|
|
1468
|
+
callbackContext.error("convertImageTo64BaseString failed, exception is : " + e.getMessage());
|
|
1422
1469
|
}
|
|
1423
1470
|
|
|
1424
1471
|
} catch (Exception e) {
|
|
@@ -1434,9 +1481,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1434
1481
|
File image = new File(filePath);
|
|
1435
1482
|
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
|
|
1436
1483
|
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
|
|
1437
|
-
|
|
1438
1484
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
1439
|
-
bitmap.compress(Bitmap.CompressFormat.
|
|
1485
|
+
bitmap.compress(Bitmap.CompressFormat.PNG, 100, outputStream);
|
|
1440
1486
|
resultString = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
|
|
1441
1487
|
} catch (Exception e) {
|
|
1442
1488
|
e.printStackTrace();
|
|
@@ -1453,7 +1499,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1453
1499
|
pluginResult.setKeepCallback(true);
|
|
1454
1500
|
callbackContext.sendPluginResult(pluginResult);
|
|
1455
1501
|
} catch (Exception e) {
|
|
1456
|
-
callbackContext.error("unable to choose file, exception is : "+e.getMessage());
|
|
1502
|
+
callbackContext.error("unable to choose file, exception is : " + e.getMessage());
|
|
1457
1503
|
}
|
|
1458
1504
|
}
|
|
1459
1505
|
|
|
@@ -1486,7 +1532,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1486
1532
|
r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
|
|
1487
1533
|
callbackContext.success(r);
|
|
1488
1534
|
} catch (Exception e) {
|
|
1489
|
-
callbackContext.error("unable to get appVersion, exception is : "+e.getMessage());
|
|
1535
|
+
callbackContext.error("unable to get appVersion, exception is : " + e.getMessage());
|
|
1490
1536
|
}
|
|
1491
1537
|
}
|
|
1492
1538
|
|
|
@@ -1519,7 +1565,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1519
1565
|
}
|
|
1520
1566
|
callbackContext.success(currentOrientation);
|
|
1521
1567
|
} catch (Exception e) {
|
|
1522
|
-
callbackContext.success("rotateScreen failed, exception is : "+e.getMessage());
|
|
1568
|
+
callbackContext.success("rotateScreen failed, exception is : " + e.getMessage());
|
|
1523
1569
|
}
|
|
1524
1570
|
}
|
|
1525
1571
|
|
|
@@ -1544,7 +1590,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1544
1590
|
r.put("applicationName", getApplicationName(cordova.getActivity()));
|
|
1545
1591
|
callbackContext.success(r);
|
|
1546
1592
|
} catch (Exception e) {
|
|
1547
|
-
callbackContext.error("unable to get deviceInfo, exception is : "+e.getMessage());
|
|
1593
|
+
callbackContext.error("unable to get deviceInfo, exception is : " + e.getMessage());
|
|
1548
1594
|
}
|
|
1549
1595
|
}
|
|
1550
1596
|
|
|
@@ -1806,13 +1852,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1806
1852
|
}
|
|
1807
1853
|
}
|
|
1808
1854
|
} catch (Exception e) {
|
|
1809
|
-
callback.error("onActivityResult failed, exception is : "+e.getMessage());
|
|
1855
|
+
callback.error("onActivityResult failed, exception is : " + e.getMessage());
|
|
1810
1856
|
}
|
|
1811
1857
|
} else {
|
|
1812
1858
|
callback.error("onActivityResult: Selected file path is null");
|
|
1813
1859
|
}
|
|
1814
1860
|
} catch (Exception e) {
|
|
1815
|
-
callback.error("onActivityResult failed, exception is : "+e.getMessage());
|
|
1861
|
+
callback.error("onActivityResult failed, exception is : " + e.getMessage());
|
|
1816
1862
|
}
|
|
1817
1863
|
} else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
|
|
1818
1864
|
if (resultCode == RESULT_OK) {
|
|
@@ -2054,7 +2100,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2054
2100
|
callback.error("Error occurred in opening outputStream");
|
|
2055
2101
|
}
|
|
2056
2102
|
} catch (Exception e) {
|
|
2057
|
-
callback.error("copyFileFromUri failed, exception is : "+e.getMessage());
|
|
2103
|
+
callback.error("copyFileFromUri failed, exception is : " + e.getMessage());
|
|
2058
2104
|
}
|
|
2059
2105
|
return outPutFilePath;
|
|
2060
2106
|
}
|
|
@@ -2108,7 +2154,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2108
2154
|
.checkLocationSettings(mGoogleApiClient1, builder.build());
|
|
2109
2155
|
result.setResultCallback(this);
|
|
2110
2156
|
} catch (Exception e) {
|
|
2111
|
-
callbackContext.error("EnableGPSAutomatically failed, exception is : "+e.getMessage());
|
|
2157
|
+
callbackContext.error("EnableGPSAutomatically failed, exception is : " + e.getMessage());
|
|
2112
2158
|
}
|
|
2113
2159
|
}
|
|
2114
2160
|
|
|
@@ -2119,7 +2165,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2119
2165
|
startLocationUpdates1();
|
|
2120
2166
|
}
|
|
2121
2167
|
} catch (Exception e) {
|
|
2122
|
-
System.out.println("GoogleApiClient failed, exception is : "+e.getMessage());
|
|
2168
|
+
System.out.println("GoogleApiClient failed, exception is : " + e.getMessage());
|
|
2123
2169
|
}
|
|
2124
2170
|
}
|
|
2125
2171
|
|
|
@@ -2151,7 +2197,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2151
2197
|
break;
|
|
2152
2198
|
}
|
|
2153
2199
|
} catch (Exception e) {
|
|
2154
|
-
System.out.println("LocationSettingsResult failed, exception is : "+e.getMessage());
|
|
2200
|
+
System.out.println("LocationSettingsResult failed, exception is : " + e.getMessage());
|
|
2155
2201
|
}
|
|
2156
2202
|
}
|
|
2157
2203
|
|
|
@@ -2165,7 +2211,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2165
2211
|
callback.success(mCurrentLocation1.getLatitude() + "," + mCurrentLocation1.getLongitude());
|
|
2166
2212
|
}
|
|
2167
2213
|
} catch (Exception e) {
|
|
2168
|
-
callback.error("onLocationChanged failed, exception is : "+e.getMessage());
|
|
2214
|
+
callback.error("onLocationChanged failed, exception is : " + e.getMessage());
|
|
2169
2215
|
}
|
|
2170
2216
|
}
|
|
2171
2217
|
|
|
@@ -2221,7 +2267,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2221
2267
|
output.write(data, 0, count);
|
|
2222
2268
|
}
|
|
2223
2269
|
} catch (Exception e) {
|
|
2224
|
-
downloadFileCallback.error("DownloadTask failed for url"+sUrl[0]+" , exception is : "+e.getMessage());
|
|
2270
|
+
downloadFileCallback.error("DownloadTask failed for url" + sUrl[0] + " , exception is : " + e.getMessage());
|
|
2225
2271
|
}
|
|
2226
2272
|
if (sUrl[2].equalsIgnoreCase("true")) {
|
|
2227
2273
|
return sUrl[1];
|
|
@@ -2247,7 +2293,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2247
2293
|
downloadFileCallback.success("");
|
|
2248
2294
|
}
|
|
2249
2295
|
} catch (Exception e) {
|
|
2250
|
-
downloadFileCallback.error("copyAttachmentFile failed, exception is : "+e.getMessage());
|
|
2296
|
+
downloadFileCallback.error("copyAttachmentFile failed, exception is : " + e.getMessage());
|
|
2251
2297
|
}
|
|
2252
2298
|
}
|
|
2253
2299
|
}
|
|
@@ -2344,7 +2390,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2344
2390
|
else
|
|
2345
2391
|
callbackContext.error("Bad zip file");
|
|
2346
2392
|
} catch (Exception e) {
|
|
2347
|
-
String errorMessage = "unzipSync failed, exception is : "+e.getMessage();
|
|
2393
|
+
String errorMessage = "unzipSync failed, exception is : " + e.getMessage();
|
|
2348
2394
|
callbackContext.error(errorMessage);
|
|
2349
2395
|
} finally {
|
|
2350
2396
|
if (inputStream != null) {
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
package com.selfservit.util;
|
|
2
2
|
|
|
3
3
|
import static com.selfservit.util.mInterfaceUtil.decrypt;
|
|
4
|
+
import static com.selfservit.util.mInterfaceUtil.rootDirectory;
|
|
4
5
|
|
|
5
6
|
import android.Manifest;
|
|
6
7
|
import android.annotation.TargetApi;
|
|
@@ -50,6 +51,7 @@ import java.net.HttpURLConnection;
|
|
|
50
51
|
import java.net.URL;
|
|
51
52
|
import java.text.DateFormat;
|
|
52
53
|
import java.text.SimpleDateFormat;
|
|
54
|
+
import java.util.ArrayList;
|
|
53
55
|
import java.util.Arrays;
|
|
54
56
|
import java.util.Date;
|
|
55
57
|
import java.util.Timer;
|
|
@@ -115,7 +117,6 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
115
117
|
}
|
|
116
118
|
};
|
|
117
119
|
setQueueToServerInterval.schedule(setQueueIntervalObj, 2000, 2000);
|
|
118
|
-
|
|
119
120
|
// App State Info Process //
|
|
120
121
|
mInterfaceUtil.validateAppStateInfo(getApplicationContext());
|
|
121
122
|
if (!isGooglePlayServicesAvailable()) {
|
|
@@ -123,8 +124,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
123
124
|
}
|
|
124
125
|
String currentLine;
|
|
125
126
|
StringBuilder locConfigObj = new StringBuilder();
|
|
126
|
-
File baseDirectory =
|
|
127
|
-
File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/
|
|
127
|
+
File baseDirectory = rootDirectory;
|
|
128
|
+
File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/app_controller.json");
|
|
128
129
|
if (locConfigFile.exists()) {
|
|
129
130
|
BufferedReader readerObj = new BufferedReader(new FileReader(locConfigFile));
|
|
130
131
|
while ((currentLine = readerObj.readLine()) != null) {
|
|
@@ -132,17 +133,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
132
133
|
}
|
|
133
134
|
readerObj.close();
|
|
134
135
|
JSONObject serverDateObj = new JSONObject(decrypt(locConfigObj.toString()));
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
if (locationCheckFile.exists()) {
|
|
139
|
-
BufferedReader readerObj1 = new BufferedReader(new FileReader(locationCheckFile));
|
|
140
|
-
while ((currentLine = readerObj1.readLine()) != null) {
|
|
141
|
-
locConfigObj1.append(currentLine);
|
|
142
|
-
}
|
|
143
|
-
readerObj1.close();
|
|
144
|
-
String locationCheckStr = decrypt(locConfigObj1.toString());
|
|
145
|
-
if (locationCheckStr.equals("false")) {
|
|
136
|
+
if (serverDateObj.has("location_check")) {
|
|
137
|
+
boolean locationCheck = serverDateObj.getBoolean("location_check");
|
|
138
|
+
if (!locationCheck) {
|
|
146
139
|
TimerTask timerTask = new TimerTask() {
|
|
147
140
|
@Override
|
|
148
141
|
public void run() {
|
|
@@ -156,8 +149,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
156
149
|
};
|
|
157
150
|
if (setLocationTimeInterval == null) {
|
|
158
151
|
setLocationTimeInterval = new Timer();
|
|
159
|
-
|
|
160
|
-
|
|
152
|
+
JSONObject locationConfig = serverDateObj.getJSONObject("location_configuration");
|
|
153
|
+
setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L));
|
|
154
|
+
MINIMUM_INTERVAL = Long.parseLong(locationConfig.getString("location_fetch_interval_in_seconds"));
|
|
161
155
|
createLocationRequest();
|
|
162
156
|
this.mGoogleApiClient = new GoogleApiClient.Builder(this)
|
|
163
157
|
.addConnectionCallbacks(this)
|
|
@@ -289,9 +283,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
289
283
|
String[] lastKnownLocation;
|
|
290
284
|
boolean result = false;
|
|
291
285
|
try {
|
|
292
|
-
baseDirectory =
|
|
286
|
+
baseDirectory = rootDirectory;
|
|
293
287
|
locationData = new StringBuilder();
|
|
294
|
-
File lastKnownLocationFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/
|
|
288
|
+
File lastKnownLocationFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/last_known_location.txt");
|
|
295
289
|
if (lastKnownLocationFile.exists()) {
|
|
296
290
|
readerObj = new BufferedReader(new FileReader(lastKnownLocationFile));
|
|
297
291
|
while ((currentLine = readerObj.readLine()) != null) {
|
|
@@ -336,30 +330,19 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
336
330
|
String statusIndication = "false";
|
|
337
331
|
try {
|
|
338
332
|
String clientID, countryCode, userID, clientUrl;
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
JSONObject currentAccount;
|
|
343
|
-
String currentLine;
|
|
344
|
-
if (new File(mInterfaceUtil.rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt").exists()) {
|
|
345
|
-
myAccountsFileReader = new BufferedReader(new FileReader(new File(mInterfaceUtil.rootDirectory, "/" + mInterfaceUtil.packageName + "/" + "my_accounts_encrypted.txt")));
|
|
346
|
-
myAccountsFileBuilder = new StringBuilder();
|
|
347
|
-
while ((currentLine = myAccountsFileReader.readLine()) != null) {
|
|
348
|
-
myAccountsFileBuilder.append(currentLine);
|
|
349
|
-
}
|
|
350
|
-
myAccountsFileReader.close();
|
|
351
|
-
accountsList = new JSONArray(decrypt(myAccountsFileBuilder.toString()));
|
|
333
|
+
ArrayList<JSONObject> accountsList;
|
|
334
|
+
if (new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").exists()) {
|
|
335
|
+
accountsList = mInterface.getJsonDataFromFiles(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").getPath());
|
|
352
336
|
if (isConnected()) {
|
|
353
|
-
for (
|
|
354
|
-
currentAccount = accountsList.optJSONObject(index);
|
|
337
|
+
for (JSONObject currentAccount : accountsList) {
|
|
355
338
|
clientID = currentAccount.optString("client_id");
|
|
356
339
|
countryCode = currentAccount.optString("country_code");
|
|
357
340
|
userID = currentAccount.optString("user_id");
|
|
358
341
|
clientUrl = currentAccount.optString("client_url");
|
|
359
|
-
File baseDirectory =
|
|
342
|
+
File baseDirectory = rootDirectory;
|
|
360
343
|
File databaseDir = new File(baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database");
|
|
361
344
|
if (databaseDir.exists()) {
|
|
362
|
-
String attachmentsPath =
|
|
345
|
+
String attachmentsPath = rootDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/attachments";
|
|
363
346
|
String queuesPath = baseDirectory + "/" + mInterfaceUtil.packageName + "/" + clientID + "/" + countryCode + "/database/queue";
|
|
364
347
|
if (new File(attachmentsPath).exists()) {
|
|
365
348
|
File[] attachmentsFiles = new File(attachmentsPath).listFiles();
|
|
@@ -436,10 +419,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
436
419
|
@Override
|
|
437
420
|
protected String doInBackground(String... urls) {
|
|
438
421
|
String currentLine, clientID, countryCode, clientUrl, deviceID;
|
|
439
|
-
|
|
440
|
-
StringBuilder myAccountsFileBuilder;
|
|
441
|
-
JSONArray accountsList;
|
|
442
|
-
JSONObject currentAccount;
|
|
422
|
+
ArrayList<JSONObject> accountsList;
|
|
443
423
|
StringBuilder locationData;
|
|
444
424
|
BufferedReader readerObj;
|
|
445
425
|
BufferedWriter writerObj;
|
|
@@ -450,30 +430,23 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
450
430
|
URL requestPath;
|
|
451
431
|
|
|
452
432
|
try {
|
|
453
|
-
File baseDirectory =
|
|
454
|
-
if (new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/"
|
|
455
|
-
|
|
456
|
-
myAccountsFileBuilder = new StringBuilder();
|
|
457
|
-
while ((currentLine = myAccountsFileReader.readLine()) != null) {
|
|
458
|
-
myAccountsFileBuilder.append(currentLine);
|
|
459
|
-
}
|
|
460
|
-
myAccountsFileReader.close();
|
|
461
|
-
accountsList = new JSONArray(decrypt(myAccountsFileBuilder.toString()));
|
|
433
|
+
File baseDirectory = rootDirectory;
|
|
434
|
+
if (new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").exists()) {
|
|
435
|
+
accountsList = mInterface.getJsonDataFromFiles(new File(rootDirectory, "/" + mInterfaceUtil.packageName + "/my_accounts").getPath());
|
|
462
436
|
locationData = new StringBuilder();
|
|
463
|
-
readerObj = new BufferedReader(new FileReader(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/
|
|
437
|
+
readerObj = new BufferedReader(new FileReader(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/my_location.txt")));
|
|
464
438
|
while ((currentLine = readerObj.readLine()) != null) {
|
|
465
439
|
locationData.append(decrypt(currentLine));
|
|
466
440
|
}
|
|
467
441
|
readerObj.close();
|
|
468
442
|
serverData = locationData.toString();
|
|
469
443
|
|
|
470
|
-
for (
|
|
471
|
-
currentAccount = accountsList.optJSONObject(index);
|
|
444
|
+
for (JSONObject currentAccount : accountsList) {
|
|
472
445
|
if (currentAccount.optString("location_update_ind").equals("true")) {
|
|
473
|
-
clientID =
|
|
474
|
-
countryCode =
|
|
475
|
-
clientUrl =
|
|
476
|
-
deviceID =
|
|
446
|
+
clientID = currentAccount.optString("client_id");
|
|
447
|
+
countryCode = currentAccount.optString("country_code");
|
|
448
|
+
clientUrl = currentAccount.optString("client_url");
|
|
449
|
+
deviceID = currentAccount.optString("device_id");
|
|
477
450
|
requestURL = clientUrl + "/common/components/GeoLocation/update_device_location_offline.aspx";
|
|
478
451
|
/* SEND LOCATION */
|
|
479
452
|
requestPath = new URL(requestURL);
|
|
@@ -491,7 +464,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
491
464
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
|
492
465
|
/* CLEARING THE LOCATION POINTS */
|
|
493
466
|
if (serverData != "") {
|
|
494
|
-
writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/
|
|
467
|
+
writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/my_location.txt")));
|
|
495
468
|
writerObj.write("");
|
|
496
469
|
writerObj.flush();
|
|
497
470
|
writerObj.close();
|
|
@@ -523,17 +496,17 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
523
496
|
@Override
|
|
524
497
|
protected String doInBackground(String... urls) {
|
|
525
498
|
File appDirectory,
|
|
526
|
-
baseDirectory =
|
|
499
|
+
baseDirectory = rootDirectory;
|
|
527
500
|
FileWriter fileWriterObj;
|
|
528
501
|
appDirectory = new File(baseDirectory + "/" + mInterfaceUtil.packageName);
|
|
529
502
|
if (appDirectory.exists()) {
|
|
530
503
|
try {
|
|
531
|
-
fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/
|
|
504
|
+
fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/my_location.txt"), true);
|
|
532
505
|
fileWriterObj.write(mInterfaceUtil.encrypt(this.objLat + "," + this.objLon + "," + new SimpleDateFormat("yyyyMMddHHmmss", new mInterfaceUtil().locale).format(new Date()) + "\n"));
|
|
533
506
|
fileWriterObj.flush();
|
|
534
507
|
fileWriterObj.close();
|
|
535
508
|
|
|
536
|
-
fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/
|
|
509
|
+
fileWriterObj = new FileWriter(new File(baseDirectory, mInterfaceUtil.packageName + "/last_known_location.txt"), false);
|
|
537
510
|
fileWriterObj.write(mInterfaceUtil.encrypt(this.objLat + "," + this.objLon + "," + new SimpleDateFormat("yyyyMMddHHmmss", new mInterfaceUtil().locale).format(new Date())));
|
|
538
511
|
fileWriterObj.flush();
|
|
539
512
|
fileWriterObj.close();
|
|
@@ -577,7 +550,7 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
577
550
|
} else {
|
|
578
551
|
restartServicePI = PendingIntent.getService(
|
|
579
552
|
getApplicationContext(), 1, restartService,
|
|
580
|
-
PendingIntent.FLAG_ONE_SHOT);
|
|
553
|
+
PendingIntent.FLAG_ONE_SHOT | PendingIntent.FLAG_IMMUTABLE);
|
|
581
554
|
}
|
|
582
555
|
|
|
583
556
|
AlarmManager alarmService = (AlarmManager) getApplicationContext().getSystemService(Context.ALARM_SERVICE);
|
|
@@ -650,8 +623,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
650
623
|
};
|
|
651
624
|
String currentLine;
|
|
652
625
|
StringBuilder locConfigObj = new StringBuilder();
|
|
653
|
-
File baseDirectory =
|
|
654
|
-
File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/
|
|
626
|
+
File baseDirectory = rootDirectory;
|
|
627
|
+
File locConfigFile = new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/app_controller.json");
|
|
655
628
|
if (locConfigFile.exists()) {
|
|
656
629
|
BufferedReader readerObj = new BufferedReader(new FileReader(locConfigFile));
|
|
657
630
|
while ((currentLine = readerObj.readLine()) != null) {
|
|
@@ -661,7 +634,9 @@ public class mInterfaceService extends Service implements com.google.android.gms
|
|
|
661
634
|
JSONObject serverDateObj = new JSONObject(decrypt(locConfigObj.toString()));
|
|
662
635
|
setLocationTimeInterval.cancel();
|
|
663
636
|
setLocationTimeInterval = new Timer();
|
|
664
|
-
|
|
637
|
+
JSONObject locationConfig = serverDateObj.getJSONObject("location_configuration");
|
|
638
|
+
setLocationTimeInterval.schedule(timerTask, (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L), (Integer.parseInt(locationConfig.getString("location_fetch_interval_in_seconds")) * 1000L));
|
|
639
|
+
MINIMUM_INTERVAL = Long.parseLong(locationConfig.getString("location_fetch_interval_in_seconds"));
|
|
665
640
|
}
|
|
666
641
|
} catch (Exception e) {
|
|
667
642
|
e.printStackTrace();
|