cordova-plugin-mserviceinterface-2.0 1.0.32 → 1.0.35

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.35",
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.35">
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,7 +13,9 @@ 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;
18
+ import android.content.res.Configuration;
17
19
  import android.database.Cursor;
18
20
  import android.graphics.Bitmap;
19
21
  import android.graphics.BitmapFactory;
@@ -30,6 +32,7 @@ import android.os.AsyncTask;
30
32
  import android.os.Build;
31
33
  import android.os.Bundle;
32
34
  import android.os.Environment;
35
+ import android.os.FileUtils;
33
36
  import android.os.PowerManager;
34
37
  import android.provider.DocumentsContract;
35
38
  import android.provider.MediaStore;
@@ -77,6 +80,7 @@ import java.io.BufferedInputStream;
77
80
  import java.io.BufferedReader;
78
81
  import java.io.ByteArrayOutputStream;
79
82
  import java.io.File;
83
+ import java.io.FileInputStream;
80
84
  import java.io.FileOutputStream;
81
85
  import java.io.IOException;
82
86
  import java.io.InputStream;
@@ -100,6 +104,9 @@ import java.util.List;
100
104
  import java.util.ArrayList;
101
105
  import java.util.Arrays;
102
106
 
107
+
108
+ import id.zelory.compressor.Compressor;
109
+
103
110
  import static android.app.Activity.RESULT_OK;
104
111
 
105
112
  public class mInterface extends CordovaPlugin implements com.google.android.gms.location.LocationListener, GoogleApiClient.ConnectionCallbacks, GoogleApiClient.OnConnectionFailedListener, ResultCallback<LocationSettingsResult> {
@@ -667,7 +674,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
667
674
  try {
668
675
  Intent intent = new Intent(Intent.ACTION_VIEW);
669
676
  Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", imageFilePath);
670
- intent.setDataAndType(contentUri, getMimeType(filePath));
677
+ intent.setDataAndType(contentUri, getMimeType(filePath,null));
671
678
  intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
672
679
  cordova.getActivity().startActivity(intent);
673
680
  callbackContext.success();
@@ -955,13 +962,18 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
955
962
  }
956
963
 
957
964
  private void checkLocationPermission(JSONArray args, CallbackContext callbackContext) {
958
- boolean permissionGranted = true;
965
+ boolean permissionGranted = true, checkPermission = true;
959
966
  List<String> list;
960
967
  try {
961
968
  callback = callbackContext;
962
969
  Context context = cordova.getActivity().getApplicationContext();
963
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
964
- String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
970
+ String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
971
+ if (permissions[0].equalsIgnoreCase("android.permission.ACCESS_BACKGROUND_LOCATION")) {
972
+ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q) {
973
+ checkPermission = false;
974
+ }
975
+ };
976
+ if (checkPermission) {
965
977
  list = new ArrayList<String>(Arrays.asList(permissions));
966
978
  permissions = list.toArray(new String[0]);
967
979
 
@@ -988,7 +1000,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
988
1000
  try {
989
1001
  callback = callbackContext;
990
1002
  Context context = cordova.getActivity().getApplicationContext();
991
- if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
992
1003
  String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
993
1004
  list = new ArrayList<String>(Arrays.asList(permissions));
994
1005
  permissions = list.toArray(new String[0]);
@@ -1003,9 +1014,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1003
1014
  } else {
1004
1015
  callback.success("success");
1005
1016
  }
1006
- } else {
1007
- callback.success("success");
1008
- }
1009
1017
  } catch (Exception e) {
1010
1018
  e.printStackTrace();
1011
1019
  }
@@ -1115,13 +1123,25 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1115
1123
  callbackContext.sendPluginResult(pluginResult);
1116
1124
  }
1117
1125
 
1118
- private static String getMimeType(String path) {
1126
+ private String getMimeType(String path,Uri uri) {
1119
1127
  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
- }
1128
+ if(uri==null){
1129
+ String extension = MimeTypeMap.getFileExtensionFromUrl(path);
1130
+ if (extension != null) {
1131
+ MimeTypeMap mime = MimeTypeMap.getSingleton();
1132
+ mimeType = mime.getMimeTypeFromExtension(extension.toLowerCase());
1133
+ }
1134
+ }else{
1135
+ if (ContentResolver.SCHEME_CONTENT.equals(uri.getScheme())) {
1136
+ ContentResolver cr = cordova.getActivity().getContentResolver();
1137
+ mimeType = cr.getType(uri);
1138
+ } else {
1139
+ String fileExtension = MimeTypeMap.getFileExtensionFromUrl(uri
1140
+ .toString());
1141
+ mimeType = MimeTypeMap.getSingleton().getMimeTypeFromExtension(
1142
+ fileExtension.toLowerCase());
1143
+ }
1144
+ };
1125
1145
  return mimeType;
1126
1146
  }
1127
1147
 
@@ -1156,6 +1176,121 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1156
1176
  }
1157
1177
 
1158
1178
  public void convertImageTo64BaseString(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1179
+ InputStream srcFileReader;
1180
+ OutputStream desFileWriter;
1181
+ byte[] buf;
1182
+ int srcFileSize;
1183
+ String compressedImagePathStr = "";
1184
+ String compressedImageName = "";
1185
+ Bitmap bitmap;
1186
+ BitmapFactory.Options options = new BitmapFactory.Options();
1187
+ options.inJustDecodeBounds = true;
1188
+ String[] bits = imageSourcePath.split("/");
1189
+
1190
+ String fileNameToSend = bits[bits.length - 1];
1191
+ if (fileNameToSend.indexOf(".") > 0)
1192
+ fileNameToSend = fileNameToSend.substring(0, fileNameToSend.lastIndexOf("."));
1193
+
1194
+ File fileToCompress = new File(imageSourcePath);
1195
+ String thumbnail = getFileThumbnail(imageSourcePath, "." + imageSourcePath.substring(imageSourcePath.lastIndexOf(".") + 1).toLowerCase());
1196
+ File compressedImageFile = null;
1197
+
1198
+ try {
1199
+ compressedImageFile = new Compressor(cordova.getActivity())
1200
+ .setQuality(15)
1201
+ .setCompressFormat(Bitmap.CompressFormat.JPEG)
1202
+ .compressToFile(fileToCompress);
1203
+
1204
+ if (imgSrcType.equals("compress")) {
1205
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1206
+ if (!destinationPath.equalsIgnoreCase("")) {
1207
+ compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + destinationPath;
1208
+ } else {
1209
+ compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images";
1210
+ }
1211
+ compressedImageName = compressedImagePathStr + "/" + fileNameToSend + "_" + timeStamp + ".jpg";
1212
+ File fileSavedPath = new File(compressedImagePathStr);
1213
+ if (!fileSavedPath.exists()) {
1214
+ fileSavedPath.mkdirs();
1215
+ }
1216
+ File sourceFileObj = compressedImageFile;
1217
+ //** CHECK SOURCE FILE EXITS OR NOT **//
1218
+ if (sourceFileObj.exists()) {
1219
+ srcFileReader = new FileInputStream(sourceFileObj);
1220
+ desFileWriter = new FileOutputStream(new File(compressedImageName));
1221
+ buf = new byte[1024];
1222
+ //** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
1223
+ while ((srcFileSize = srcFileReader.read(buf)) > 0) {
1224
+ desFileWriter.write(buf, 0, srcFileSize);
1225
+ }
1226
+ srcFileReader.close();
1227
+ desFileWriter.close();
1228
+ }
1229
+ bitmap = BitmapFactory.decodeFile(compressedImageName);
1230
+
1231
+ } else {
1232
+ bitmap = BitmapFactory.decodeFile(compressedImageFile.getAbsolutePath());
1233
+ }
1234
+ String encodedImage = null;
1235
+ try {
1236
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1237
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 15, outputStream);
1238
+ Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1239
+ encodedImage = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1240
+ if (imgSrcType.equals("camera")) {
1241
+ File file = new File(imageSourcePath);
1242
+ if (file.exists()) {
1243
+ file.delete();
1244
+ }
1245
+ attachmentDestPath = "";
1246
+ callbackContext.success(encodedImage);
1247
+ } else if (imgSrcType.equals("gallery")) {
1248
+ attachmentDestPath = "";
1249
+ callbackContext.success(encodedImage);
1250
+ } else if (imgSrcType.equals("compress")) {
1251
+ try {
1252
+
1253
+ if (!destinationPath.equalsIgnoreCase("")) {
1254
+ File file = new File(imageSourcePath);
1255
+ if (file.exists()) {
1256
+ file.delete();
1257
+ }
1258
+ }
1259
+ JSONObject fileProperities = null;
1260
+ String imgFilePath, fileName, fileExtension = "";
1261
+ imgFilePath = compressedImageName.substring(0, compressedImageName.lastIndexOf("/"));
1262
+ String[] fileName1 = compressedImageName.split("/");
1263
+ fileName = fileName1[fileName1.length - 1];
1264
+ File file = new File(compressedImageName);
1265
+ long fileSize = file.length();
1266
+ fileExtension = "." + compressedImageName.substring(compressedImageName.lastIndexOf(".") + 1).toLowerCase();
1267
+ fileProperities = new JSONObject();
1268
+ fileProperities.put("filePath", imgFilePath);
1269
+ fileProperities.put("fileName", fileName);
1270
+ fileProperities.put("fileSize", fileSize);
1271
+ fileProperities.put("fileExtension", fileExtension);
1272
+ fileProperities.put("thumbnail", thumbnail);
1273
+ attachmentDestPath = "";
1274
+ callback.success(fileProperities);
1275
+ } catch (Exception e) {
1276
+ attachmentDestPath = "";
1277
+ callback.error(e.getMessage());
1278
+ }
1279
+ }
1280
+ } catch (Exception e) {
1281
+ attachmentDestPath = "";
1282
+ callbackContext.error(e.getMessage());
1283
+ }
1284
+
1285
+ } catch (IOException e) {
1286
+ e.printStackTrace();
1287
+ }
1288
+
1289
+ }
1290
+
1291
+
1292
+
1293
+ public void convertImageTo64BaseString1(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1159
1294
  String compressedImagePathStr = "";
1160
1295
  String compressedImageName = "";
1161
1296
  String filePath = imageSourcePath;
@@ -1374,7 +1509,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1374
1509
  //Rotate Screen plugin
1375
1510
  public void rotateScreen(JSONArray args, CallbackContext callbackContext) {
1376
1511
  String orientation = args.optString(0);
1512
+ String currentOrientation = "";
1377
1513
  Activity activity = cordova.getActivity();
1514
+ int orientation1 = activity.getResources().getConfiguration().orientation;
1515
+ if (orientation1 == Configuration.ORIENTATION_LANDSCAPE) {
1516
+ currentOrientation = "landscape";
1517
+ } else {
1518
+ currentOrientation = "portrait";
1519
+ };
1378
1520
  if (orientation.equals(ANY)) {
1379
1521
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1380
1522
  } else if (orientation.equals(LANDSCAPE_PRIMARY)) {
@@ -1390,7 +1532,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1390
1532
  } else if (orientation.equals(PORTRAIT_SECONDARY)) {
1391
1533
  activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
1392
1534
  }
1393
- callbackContext.success();
1535
+ callbackContext.success(currentOrientation);
1394
1536
  }
1395
1537
 
1396
1538
  public void deviceInfo(CallbackContext callbackContext) throws JSONException {
@@ -1410,8 +1552,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1410
1552
  r.put("timeZone", TimeZone.getDefault());
1411
1553
  r.put("sdkVersion", sdkversion);
1412
1554
  r.put("productName", android.os.Build.PRODUCT);
1555
+ r.put("applicationName", getApplicationName(cordova.getActivity()));
1413
1556
  callbackContext.success(r);
1414
1557
  }
1558
+ public static String getApplicationName(Context context) {
1559
+ ApplicationInfo applicationInfo = context.getApplicationInfo();
1560
+ int stringId = applicationInfo.labelRes;
1561
+ return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
1562
+ }
1415
1563
 
1416
1564
  @Override
1417
1565
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
@@ -1602,6 +1750,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1602
1750
  fileName = fileName + "_" + timeStamp + extension;
1603
1751
  }
1604
1752
 
1753
+ }else{
1754
+ fileName = uri.getLastPathSegment();
1605
1755
  }
1606
1756
  } finally {
1607
1757
  if (cursor != null) {
@@ -1614,7 +1764,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1614
1764
 
1615
1765
  filePath = copyFileFromUri(cordova.getActivity().getApplicationContext(), uri, fileName, attachmentDestPath,callback);
1616
1766
  File file = new File(filePath);
1617
- String mimeType = getMimeType(filePath);
1767
+ String mimeType = getMimeType(filePath,uri);
1618
1768
  System.out.println("Mime type is: " + mimeType);
1619
1769
  double fileSize = file.length();
1620
1770
  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
  }