cordova-plugin-mserviceinterface-2.0 1.0.63 → 1.0.64
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 +47 -208
- package/src/android/mInterfaceUtil.java +116 -25
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.64">
|
|
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
|
-
|
|
161
|
-
|
|
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.
|
|
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")) {
|
|
@@ -875,7 +875,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
875
875
|
}
|
|
876
876
|
} catch (JSONException e) {
|
|
877
877
|
e.printStackTrace();
|
|
878
|
-
result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
|
878
|
+
result = new PluginResult(PluginResult.Status.ERROR, "OpenSms failed, exception is : "+e.getMessage());
|
|
879
879
|
callback.sendPluginResult(result);
|
|
880
880
|
}
|
|
881
881
|
return true;
|
|
@@ -944,7 +944,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
944
944
|
}
|
|
945
945
|
} catch (Exception e) {
|
|
946
946
|
e.printStackTrace();
|
|
947
|
-
result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
|
947
|
+
result = new PluginResult(PluginResult.Status.ERROR, "OpenEmail failed, exception is : "+e.getMessage());
|
|
948
948
|
callback.sendPluginResult(result);
|
|
949
949
|
}
|
|
950
950
|
|
|
@@ -958,13 +958,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
958
958
|
callbackContext.success("success");
|
|
959
959
|
} catch (Exception e) {
|
|
960
960
|
e.printStackTrace();
|
|
961
|
-
result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
|
961
|
+
result = new PluginResult(PluginResult.Status.ERROR, "copyAttachmentFile failed, exception is : "+e.getMessage());
|
|
962
962
|
callback.sendPluginResult(result);
|
|
963
963
|
}
|
|
964
964
|
|
|
965
965
|
}
|
|
966
966
|
} catch (JSONException e) {
|
|
967
|
-
System.out.println("
|
|
967
|
+
System.out.println(" unable to proccess plugin method, exception is : "+e.getMessage());
|
|
968
968
|
}
|
|
969
969
|
return true;
|
|
970
970
|
}
|
|
@@ -1044,7 +1044,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1044
1044
|
pluginResult.setKeepCallback(true);
|
|
1045
1045
|
callbackContext.sendPluginResult(pluginResult);
|
|
1046
1046
|
} catch (Exception e) {
|
|
1047
|
-
callbackContext.error(e.getMessage());
|
|
1047
|
+
callbackContext.error("scanQRCode failed, exception is : "+e.getMessage());
|
|
1048
1048
|
}
|
|
1049
1049
|
}
|
|
1050
1050
|
|
|
@@ -1064,7 +1064,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1064
1064
|
pluginResult.setKeepCallback(true);
|
|
1065
1065
|
callbackContext.sendPluginResult(pluginResult);
|
|
1066
1066
|
} catch (Exception e) {
|
|
1067
|
-
callbackContext.error(e.getMessage());
|
|
1067
|
+
callbackContext.error("scanBarCode failed, exception is : "+e.getMessage());
|
|
1068
1068
|
}
|
|
1069
1069
|
}
|
|
1070
1070
|
|
|
@@ -1072,7 +1072,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1072
1072
|
try {
|
|
1073
1073
|
callbackContext.success("file://" + mInterfaceUtil.rootDirectory + "/");
|
|
1074
1074
|
} catch (Exception e) {
|
|
1075
|
-
callbackContext.error(e.getMessage());
|
|
1075
|
+
callbackContext.error("getStorageRoot failed, exception is : "+e.getMessage());
|
|
1076
1076
|
}
|
|
1077
1077
|
}
|
|
1078
1078
|
|
|
@@ -1168,7 +1168,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1168
1168
|
callback.success("success");
|
|
1169
1169
|
}
|
|
1170
1170
|
} catch (Exception e) {
|
|
1171
|
-
callback.error(e.getMessage());
|
|
1171
|
+
callback.error("getPermissions failed, exception is : "+e.getMessage());
|
|
1172
1172
|
}
|
|
1173
1173
|
}
|
|
1174
1174
|
|
|
@@ -1244,7 +1244,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1244
1244
|
pluginResult.setKeepCallback(true);
|
|
1245
1245
|
callbackContext.sendPluginResult(pluginResult);
|
|
1246
1246
|
} catch (Exception e) {
|
|
1247
|
-
callbackContext.error(e.getMessage());
|
|
1247
|
+
callbackContext.error("pickImageFromGallery failed, exception is : "+e.getMessage());
|
|
1248
1248
|
}
|
|
1249
1249
|
}
|
|
1250
1250
|
|
|
@@ -1410,12 +1410,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1410
1410
|
callback.success(fileProperities);
|
|
1411
1411
|
} catch (Exception e) {
|
|
1412
1412
|
attachmentDestPath = "";
|
|
1413
|
-
callback.error(e.getMessage());
|
|
1413
|
+
callback.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
|
|
1414
1414
|
}
|
|
1415
1415
|
}
|
|
1416
1416
|
} catch (Exception e) {
|
|
1417
1417
|
attachmentDestPath = "";
|
|
1418
|
-
callbackContext.error(e.getMessage());
|
|
1418
|
+
callbackContext.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
|
|
1419
1419
|
}
|
|
1420
1420
|
|
|
1421
1421
|
} catch (Exception e) {
|
|
@@ -1424,167 +1424,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1424
1424
|
|
|
1425
1425
|
}
|
|
1426
1426
|
|
|
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
1427
|
public String getBase64String(String imageSourcePath) {
|
|
1589
1428
|
String resultString = "";
|
|
1590
1429
|
try {
|
|
@@ -1611,7 +1450,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1611
1450
|
pluginResult.setKeepCallback(true);
|
|
1612
1451
|
callbackContext.sendPluginResult(pluginResult);
|
|
1613
1452
|
} catch (Exception e) {
|
|
1614
|
-
callbackContext.error(e.getMessage());
|
|
1453
|
+
callbackContext.error("unable to choose file, exception is : "+e.getMessage());
|
|
1615
1454
|
}
|
|
1616
1455
|
}
|
|
1617
1456
|
|
|
@@ -1644,7 +1483,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1644
1483
|
r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
|
|
1645
1484
|
callbackContext.success(r);
|
|
1646
1485
|
} catch (Exception e) {
|
|
1647
|
-
callbackContext.error(e.getMessage());
|
|
1486
|
+
callbackContext.error("unable to get appVersion, exception is : "+e.getMessage());
|
|
1648
1487
|
}
|
|
1649
1488
|
}
|
|
1650
1489
|
|
|
@@ -1677,7 +1516,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1677
1516
|
}
|
|
1678
1517
|
callbackContext.success(currentOrientation);
|
|
1679
1518
|
} catch (Exception e) {
|
|
1680
|
-
callbackContext.success(e.getMessage());
|
|
1519
|
+
callbackContext.success("rotateScreen failed, exception is : "+e.getMessage());
|
|
1681
1520
|
}
|
|
1682
1521
|
}
|
|
1683
1522
|
|
|
@@ -1702,7 +1541,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1702
1541
|
r.put("applicationName", getApplicationName(cordova.getActivity()));
|
|
1703
1542
|
callbackContext.success(r);
|
|
1704
1543
|
} catch (Exception e) {
|
|
1705
|
-
callbackContext.error(e.getMessage());
|
|
1544
|
+
callbackContext.error("unable to get deviceInfo, exception is : "+e.getMessage());
|
|
1706
1545
|
}
|
|
1707
1546
|
}
|
|
1708
1547
|
|
|
@@ -1964,13 +1803,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1964
1803
|
}
|
|
1965
1804
|
}
|
|
1966
1805
|
} catch (Exception e) {
|
|
1967
|
-
callback.error(e.getMessage());
|
|
1806
|
+
callback.error("onActivityResult failed, exception is : "+e.getMessage());
|
|
1968
1807
|
}
|
|
1969
1808
|
} else {
|
|
1970
|
-
callback.error("Selected file path is null");
|
|
1809
|
+
callback.error("onActivityResult: Selected file path is null");
|
|
1971
1810
|
}
|
|
1972
1811
|
} catch (Exception e) {
|
|
1973
|
-
callback.error(e.getMessage());
|
|
1812
|
+
callback.error("onActivityResult failed, exception is : "+e.getMessage());
|
|
1974
1813
|
}
|
|
1975
1814
|
} else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
|
|
1976
1815
|
if (resultCode == RESULT_OK) {
|
|
@@ -2212,7 +2051,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2212
2051
|
callback.error("Error occurred in opening outputStream");
|
|
2213
2052
|
}
|
|
2214
2053
|
} catch (Exception e) {
|
|
2215
|
-
callback.error("
|
|
2054
|
+
callback.error("copyFileFromUri failed, exception is : "+e.getMessage());
|
|
2216
2055
|
}
|
|
2217
2056
|
return outPutFilePath;
|
|
2218
2057
|
}
|
|
@@ -2266,7 +2105,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2266
2105
|
.checkLocationSettings(mGoogleApiClient1, builder.build());
|
|
2267
2106
|
result.setResultCallback(this);
|
|
2268
2107
|
} catch (Exception e) {
|
|
2269
|
-
callbackContext.error(e.getMessage());
|
|
2108
|
+
callbackContext.error("EnableGPSAutomatically failed, exception is : "+e.getMessage());
|
|
2270
2109
|
}
|
|
2271
2110
|
}
|
|
2272
2111
|
|
|
@@ -2277,7 +2116,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2277
2116
|
startLocationUpdates1();
|
|
2278
2117
|
}
|
|
2279
2118
|
} catch (Exception e) {
|
|
2280
|
-
System.out.println(e.getMessage());
|
|
2119
|
+
System.out.println("GoogleApiClient failed, exception is : "+e.getMessage());
|
|
2281
2120
|
}
|
|
2282
2121
|
}
|
|
2283
2122
|
|
|
@@ -2309,7 +2148,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2309
2148
|
break;
|
|
2310
2149
|
}
|
|
2311
2150
|
} catch (Exception e) {
|
|
2312
|
-
System.out.println(e.getMessage());
|
|
2151
|
+
System.out.println("LocationSettingsResult failed, exception is : "+e.getMessage());
|
|
2313
2152
|
}
|
|
2314
2153
|
}
|
|
2315
2154
|
|
|
@@ -2323,7 +2162,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2323
2162
|
callback.success(mCurrentLocation1.getLatitude() + "," + mCurrentLocation1.getLongitude());
|
|
2324
2163
|
}
|
|
2325
2164
|
} catch (Exception e) {
|
|
2326
|
-
callback.error(e.getMessage());
|
|
2165
|
+
callback.error("onLocationChanged failed, exception is : "+e.getMessage());
|
|
2327
2166
|
}
|
|
2328
2167
|
}
|
|
2329
2168
|
|
|
@@ -2379,7 +2218,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2379
2218
|
output.write(data, 0, count);
|
|
2380
2219
|
}
|
|
2381
2220
|
} catch (Exception e) {
|
|
2382
|
-
downloadFileCallback.error("
|
|
2221
|
+
downloadFileCallback.error("DownloadTask failed for url"+sUrl[0]+" , exception is : "+e.getMessage());
|
|
2383
2222
|
}
|
|
2384
2223
|
if (sUrl[2].equalsIgnoreCase("true")) {
|
|
2385
2224
|
return sUrl[1];
|
|
@@ -2405,7 +2244,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2405
2244
|
downloadFileCallback.success("");
|
|
2406
2245
|
}
|
|
2407
2246
|
} catch (Exception e) {
|
|
2408
|
-
downloadFileCallback.error(e.getMessage());
|
|
2247
|
+
downloadFileCallback.error("copyAttachmentFile failed, exception is : "+e.getMessage());
|
|
2409
2248
|
}
|
|
2410
2249
|
}
|
|
2411
2250
|
}
|
|
@@ -2502,7 +2341,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2502
2341
|
else
|
|
2503
2342
|
callbackContext.error("Bad zip file");
|
|
2504
2343
|
} catch (Exception e) {
|
|
2505
|
-
String errorMessage = e.getMessage();
|
|
2344
|
+
String errorMessage = "unzipSync failed, exception is : "+e.getMessage();
|
|
2506
2345
|
callbackContext.error(errorMessage);
|
|
2507
2346
|
} finally {
|
|
2508
2347
|
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("
|
|
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
|
|
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("
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|