cordova-plugin-mserviceinterface-2.0 1.0.32 → 1.0.33

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.32",
3
+ "version": "1.0.33",
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.32">
5
+ version="1.0.33">
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>
@@ -24,6 +24,7 @@
24
24
  <framework src="com.android.support:support-v4:26.0.1" />
25
25
  <framework src="com.google.zxing:core:3.2.1" />
26
26
  <framework src="com.journeyapps:zxing-android-embedded:3.2.0@aar" />
27
+ <framework src="id.zelory:compressor:2.1.1" />
27
28
  <edit-config xmlns:android="http://schemas.android.com/apk/res/android" file="AndroidManifest.xml" mode="merge" target="/manifest/application">
28
29
  <application android:networkSecurityConfig="@xml/network_security_config" />
29
30
  <application android:requestLegacyExternalStorage="true" />
@@ -13,6 +13,7 @@ import android.content.DialogInterface;
13
13
  import android.content.Intent;
14
14
  import android.content.IntentSender;
15
15
  import android.content.pm.ActivityInfo;
16
+ import android.content.pm.ApplicationInfo;
16
17
  import android.content.pm.PackageManager;
17
18
  import android.database.Cursor;
18
19
  import android.graphics.Bitmap;
@@ -30,6 +31,7 @@ import android.os.AsyncTask;
30
31
  import android.os.Build;
31
32
  import android.os.Bundle;
32
33
  import android.os.Environment;
34
+ import android.os.FileUtils;
33
35
  import android.os.PowerManager;
34
36
  import android.provider.DocumentsContract;
35
37
  import android.provider.MediaStore;
@@ -77,6 +79,7 @@ import java.io.BufferedInputStream;
77
79
  import java.io.BufferedReader;
78
80
  import java.io.ByteArrayOutputStream;
79
81
  import java.io.File;
82
+ import java.io.FileInputStream;
80
83
  import java.io.FileOutputStream;
81
84
  import java.io.IOException;
82
85
  import java.io.InputStream;
@@ -100,6 +103,9 @@ import java.util.List;
100
103
  import java.util.ArrayList;
101
104
  import java.util.Arrays;
102
105
 
106
+
107
+ import id.zelory.compressor.Compressor;
108
+
103
109
  import static android.app.Activity.RESULT_OK;
104
110
 
105
111
  public class mInterface extends CordovaPlugin implements com.google.android.gms.location.LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, ResultCallback<LocationSettingsResult> {
@@ -667,7 +673,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
667
673
  try {
668
674
  Intent intent = new Intent(Intent.ACTION_VIEW);
669
675
  Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", imageFilePath);
670
- intent.setDataAndType(contentUri, getMimeType(filePath));
676
+ intent.setDataAndType(contentUri, getMimeType(filePath,null));
671
677
  intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
672
678
  cordova.getActivity().startActivity(intent);
673
679
  callbackContext.success();
@@ -955,13 +961,18 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
955
961
  }
956
962
 
957
963
  private void checkLocationPermission(JSONArray args, CallbackContext callbackContext) {
958
- boolean permissionGranted = true;
964
+ boolean permissionGranted = true, checkPermission = true;
959
965
  List<String> list;
960
966
  try {
961
967
  callback = callbackContext;
962
968
  Context context = cordova.getActivity().getApplicationContext();
963
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
964
- String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
969
+ String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
970
+ if (permissions[0].equalsIgnoreCase("android.permission.ACCESS_BACKGROUND_LOCATION")) {
971
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
972
+ checkPermission = false;
973
+ }
974
+ };
975
+ if (checkPermission) {
965
976
  list = new ArrayList<String>(Arrays.asList(permissions));
966
977
  permissions = list.toArray(new String[0]);
967
978
 
@@ -988,7 +999,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
988
999
  try {
989
1000
  callback = callbackContext;
990
1001
  Context context = cordova.getActivity().getApplicationContext();
991
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
992
1002
  String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
993
1003
  list = new ArrayList<String>(Arrays.asList(permissions));
994
1004
  permissions = list.toArray(new String[0]);
@@ -1003,9 +1013,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1003
1013
  } else {
1004
1014
  callback.success("success");
1005
1015
  }
1006
- } else {
1007
- callback.success("success");
1008
- }
1009
1016
  } catch (Exception e) {
1010
1017
  e.printStackTrace();
1011
1018
  }
@@ -1115,13 +1122,25 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1115
1122
  callbackContext.sendPluginResult(pluginResult);
1116
1123
  }
1117
1124
 
1118
- private static String getMimeType(String path) {
1125
+ private String getMimeType(String path,Uri uri) {
1119
1126
  String mimeType = null;
1120
- String extension = MimeTypeMap.getFileExtensionFromUrl(path);
1121
- if (extension != null) {
1122
- MimeTypeMap mime = MimeTypeMap.getSingleton();
1123
- mimeType = mime.getMimeTypeFromExtension(extension.toLowerCase());
1124
- }
1127
+ if(uri==null){
1128
+ String extension = MimeTypeMap.getFileExtensionFromUrl(path);
1129
+ if (extension != null) {
1130
+ MimeTypeMap mime = MimeTypeMap.getSingleton();
1131
+ mimeType = mime.getMimeTypeFromExtension(extension.toLowerCase());
1132
+ }
1133
+ }else{
1134
+ if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
1135
+ ContentResolver cr = cordova.getActivity().getContentResolver();
1136
+ mimeType = cr.getType(uri);
1137
+ } else {
1138
+ String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri
1139
+ .toString());
1140
+ mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
1141
+ fileExtension.toLowerCase());
1142
+ }
1143
+ };
1125
1144
  return mimeType;
1126
1145
  }
1127
1146
 
@@ -1156,6 +1175,121 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1156
1175
  }
1157
1176
 
1158
1177
  public void convertImageTo64BaseString(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1178
+ InputStream srcFileReader;
1179
+ OutputStream desFileWriter;
1180
+ byte[] buf;
1181
+ int srcFileSize;
1182
+ String compressedImagePathStr = "";
1183
+ String compressedImageName = "";
1184
+ Bitmap bitmap;
1185
+ BitmapFactory.Options options = new BitmapFactory.Options();
1186
+ options.inJustDecodeBounds = true;
1187
+ String[] bits = imageSourcePath.split("/");
1188
+
1189
+ String fileNameToSend = bits[bits.length - 1];
1190
+ if (fileNameToSend.indexOf(".") > 0)
1191
+ fileNameToSend = fileNameToSend.substring(0, fileNameToSend.lastIndexOf("."));
1192
+
1193
+ File fileToCompress = new File(imageSourcePath);
1194
+ String thumbnail = getFileThumbnail(imageSourcePath, "." + imageSourcePath.substring(imageSourcePath.lastIndexOf(".") + 1).toLowerCase());
1195
+ File compressedImageFile = null;
1196
+
1197
+ try {
1198
+ compressedImageFile = new Compressor(cordova.getActivity())
1199
+ .setQuality(15)
1200
+ .setCompressFormat(Bitmap.CompressFormat.JPEG)
1201
+ .compressToFile(fileToCompress);
1202
+
1203
+ if (imgSrcType.equals("compress")) {
1204
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1205
+ if (!destinationPath.equalsIgnoreCase("")) {
1206
+ compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + destinationPath;
1207
+ } else {
1208
+ compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images";
1209
+ }
1210
+ compressedImageName = compressedImagePathStr + "/" + fileNameToSend + "_" + timeStamp + ".jpg";
1211
+ File fileSavedPath = new File(compressedImagePathStr);
1212
+ if (!fileSavedPath.exists()) {
1213
+ fileSavedPath.mkdirs();
1214
+ }
1215
+ File sourceFileObj = compressedImageFile;
1216
+ //** CHECK SOURCE FILE EXITS OR NOT **//
1217
+ if (sourceFileObj.exists()) {
1218
+ srcFileReader = new FileInputStream(sourceFileObj);
1219
+ desFileWriter = new FileOutputStream(new File(compressedImageName));
1220
+ buf = new byte[1024];
1221
+ //** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
1222
+ while ((srcFileSize = srcFileReader.read(buf)) > 0) {
1223
+ desFileWriter.write(buf, 0, srcFileSize);
1224
+ }
1225
+ srcFileReader.close();
1226
+ desFileWriter.close();
1227
+ }
1228
+ bitmap = BitmapFactory.decodeFile(compressedImageName);
1229
+
1230
+ } else {
1231
+ bitmap = BitmapFactory.decodeFile(compressedImageFile.getAbsolutePath());
1232
+ }
1233
+ String encodedImage = null;
1234
+ try {
1235
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1236
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 10, outputStream);
1237
+ Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1238
+ encodedImage = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1239
+ if (imgSrcType.equals("camera")) {
1240
+ File file = new File(imageSourcePath);
1241
+ if (file.exists()) {
1242
+ file.delete();
1243
+ }
1244
+ attachmentDestPath = "";
1245
+ callbackContext.success(encodedImage);
1246
+ } else if (imgSrcType.equals("gallery")) {
1247
+ attachmentDestPath = "";
1248
+ callbackContext.success(encodedImage);
1249
+ } else if (imgSrcType.equals("compress")) {
1250
+ try {
1251
+
1252
+ if (!destinationPath.equalsIgnoreCase("")) {
1253
+ File file = new File(imageSourcePath);
1254
+ if (file.exists()) {
1255
+ file.delete();
1256
+ }
1257
+ }
1258
+ JSONObject fileProperities = null;
1259
+ String imgFilePath, fileName, fileExtension = "";
1260
+ imgFilePath = compressedImageName.substring(0, compressedImageName.lastIndexOf("/"));
1261
+ String[] fileName1 = compressedImageName.split("/");
1262
+ fileName = fileName1[fileName1.length - 1];
1263
+ File file = new File(compressedImageName);
1264
+ long fileSize = file.length();
1265
+ fileExtension = "." + compressedImageName.substring(compressedImageName.lastIndexOf(".") + 1).toLowerCase();
1266
+ fileProperities = new JSONObject();
1267
+ fileProperities.put("filePath", imgFilePath);
1268
+ fileProperities.put("fileName", fileName);
1269
+ fileProperities.put("fileSize", fileSize);
1270
+ fileProperities.put("fileExtension", fileExtension);
1271
+ fileProperities.put("thumbnail", thumbnail);
1272
+ attachmentDestPath = "";
1273
+ callback.success(fileProperities);
1274
+ } catch (Exception e) {
1275
+ attachmentDestPath = "";
1276
+ callback.error(e.getMessage());
1277
+ }
1278
+ }
1279
+ } catch (Exception e) {
1280
+ attachmentDestPath = "";
1281
+ callbackContext.error(e.getMessage());
1282
+ }
1283
+
1284
+ } catch (IOException e) {
1285
+ e.printStackTrace();
1286
+ }
1287
+
1288
+ }
1289
+
1290
+
1291
+
1292
+ public void convertImageTo64BaseString1(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1159
1293
  String compressedImagePathStr = "";
1160
1294
  String compressedImageName = "";
1161
1295
  String filePath = imageSourcePath;
@@ -1410,8 +1544,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1410
1544
  r.put("timeZone", TimeZone.getDefault());
1411
1545
  r.put("sdkVersion", sdkversion);
1412
1546
  r.put("productName", android.os.Build.PRODUCT);
1547
+ r.put("applicationName", getApplicationName(cordova.getActivity()));
1413
1548
  callbackContext.success(r);
1414
1549
  }
1550
+ public static String getApplicationName(Context context) {
1551
+ ApplicationInfo applicationInfo = context.getApplicationInfo();
1552
+ int stringId = applicationInfo.labelRes;
1553
+ return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
1554
+ }
1415
1555
 
1416
1556
  @Override
1417
1557
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
@@ -1602,6 +1742,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1602
1742
  fileName = fileName + "_" + timeStamp + extension;
1603
1743
  }
1604
1744
 
1745
+ }else{
1746
+ fileName = uri.getLastPathSegment();
1605
1747
  }
1606
1748
  } finally {
1607
1749
  if (cursor != null) {
@@ -1614,7 +1756,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1614
1756
 
1615
1757
  filePath = copyFileFromUri(cordova.getActivity().getApplicationContext(), uri, fileName, attachmentDestPath,callback);
1616
1758
  File file = new File(filePath);
1617
- String mimeType = getMimeType(filePath);
1759
+ String mimeType = getMimeType(filePath,uri);
1618
1760
  System.out.println("Mime type is: " + mimeType);
1619
1761
  double fileSize = file.length();
1620
1762
  if (filePath != null) {
@@ -220,7 +220,8 @@ public class mInterfaceService extends Service implements com.google.android.gms
220
220
  .build();
221
221
  mGoogleApiClient.connect();
222
222
  };
223
-
223
+ getPeriodicalLocationUpdates();
224
+ update();
224
225
  }
225
226
  }
226
227
  } else {
@@ -542,19 +543,10 @@ public class mInterfaceService extends Service implements com.google.android.gms
542
543
  readerObj = new BufferedReader(new FileReader(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/MyLocation_encrypted.txt")));
543
544
  while ((currentLine = readerObj.readLine()) != null) {
544
545
  locationData.append(decrypt(currentLine));
545
- //lastKnownLocation = currentLine + "\n";
546
546
  }
547
547
  readerObj.close();
548
548
  serverData = locationData.toString();
549
549
 
550
- /* CLEARING THE LOCATION POINTS */
551
- if (serverData != "") {
552
- writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/MyLocation_encrypted.txt")));
553
- writerObj.write("");
554
- writerObj.flush();
555
- writerObj.close();
556
- }
557
-
558
550
  for (int index = 0; index < accountsList.length(); index++) {
559
551
  currentAccount = accountsList.optJSONObject(index);
560
552
  if (currentAccount.optString("location_update_ind").toString().equals("true")) {
@@ -581,8 +573,18 @@ public class mInterfaceService extends Service implements com.google.android.gms
581
573
  oStreamObj.write("<location_xml><client_id>" + clientID + "</client_id><country_code>" + countryCode + "</country_code><device_id>" + deviceID + "</device_id><location>" + serverData + "</location></location_xml>");
582
574
  oStreamObj.flush();
583
575
  oStreamObj.close();
584
- urlConObj.getResponseCode();
576
+ int responseCode = urlConObj.getResponseCode();
577
+
585
578
  urlConObj.disconnect();
579
+ if(responseCode == HttpURLConnection.HTTP_OK){
580
+ /* CLEARING THE LOCATION POINTS */
581
+ if (serverData != "") {
582
+ writerObj = new BufferedWriter(new FileWriter(new File(baseDirectory, "/" + mInterfaceUtil.packageName + "/MyLocation_encrypted.txt")));
583
+ writerObj.write("");
584
+ writerObj.flush();
585
+ writerObj.close();
586
+ }
587
+ }
586
588
  } else {
587
589
  System.out.println("Location should not be updated for this user..");
588
590
  }