cordova-plugin-mserviceinterface-2.0 1.0.24 → 1.0.28
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 +3 -2
- package/src/android/mInterface.java +125 -6
- package/src/ios/mInterface.h +2 -0
- package/src/ios/mInterface.m +17 -0
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.28">
|
|
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>
|
|
@@ -46,9 +46,10 @@
|
|
|
46
46
|
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
|
|
47
47
|
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
|
|
48
48
|
<uses-permission android:name="android.permission.READ_PHONE_STATE" />
|
|
49
|
+
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
|
|
49
50
|
</config-file>
|
|
50
51
|
<config-file target="AndroidManifest.xml" parent="/manifest/application">
|
|
51
|
-
|
|
52
|
+
<service android:name="com.selfservit.util.mInterfaceService" android:foregroundServiceType="location" android:enabled="true" android:exported="true"/>
|
|
52
53
|
<service
|
|
53
54
|
android:name="com.selfservit.util.backgroundNotification"
|
|
54
55
|
android:permission="android.permission.BIND_JOB_SERVICE"
|
|
@@ -86,6 +86,8 @@ import java.io.OutputStreamWriter;
|
|
|
86
86
|
import java.net.HttpURLConnection;
|
|
87
87
|
import java.net.URL;
|
|
88
88
|
import java.text.SimpleDateFormat;
|
|
89
|
+
import java.util.ArrayList;
|
|
90
|
+
import java.util.Arrays;
|
|
89
91
|
import java.util.Date;
|
|
90
92
|
import java.util.List;
|
|
91
93
|
import java.util.Stack;
|
|
@@ -94,6 +96,9 @@ import java.util.regex.Matcher;
|
|
|
94
96
|
import java.util.regex.Pattern;
|
|
95
97
|
import java.util.zip.ZipEntry;
|
|
96
98
|
import java.util.zip.ZipInputStream;
|
|
99
|
+
import java.util.List;
|
|
100
|
+
import java.util.ArrayList;
|
|
101
|
+
import java.util.Arrays;
|
|
97
102
|
|
|
98
103
|
import static android.app.Activity.RESULT_OK;
|
|
99
104
|
|
|
@@ -104,6 +109,8 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
104
109
|
public CallbackContext callback;
|
|
105
110
|
private static JSONArray arguments = null;
|
|
106
111
|
private String pictureFilePath;
|
|
112
|
+
private String cameraAttachmentInd = "false";
|
|
113
|
+
private String galleryAttachmentInd = "false";
|
|
107
114
|
private static final int REQUEST_IMAGE_CAPTURE = 111;
|
|
108
115
|
private static final int PICK_IMAGE_FROM_GALLERY = 112;
|
|
109
116
|
private static final int REQUEST_LIVE_IMAGE_CAPTURE = 113;
|
|
@@ -280,6 +287,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
280
287
|
} else if (action.equals("GetPermissions")) {
|
|
281
288
|
getPermissions(args, callbackContext);
|
|
282
289
|
return true;
|
|
290
|
+
} else if (action.equals("GetLocationPermission")) {
|
|
291
|
+
getLocationPermission(args, callbackContext);
|
|
292
|
+
return true;
|
|
293
|
+
} else if (action.equals("CheckLocationPermission")) {
|
|
294
|
+
checkLocationPermission(args, callbackContext);
|
|
295
|
+
return true;
|
|
283
296
|
} else if (action.equals("AppVersion")) {
|
|
284
297
|
appVersion(callbackContext);
|
|
285
298
|
return true;
|
|
@@ -663,6 +676,10 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
663
676
|
}
|
|
664
677
|
} else if (action.equals("CaptureImageFromCamera")) {
|
|
665
678
|
try {
|
|
679
|
+
if(args.length()>0){
|
|
680
|
+
attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
|
|
681
|
+
cameraAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
|
|
682
|
+
}
|
|
666
683
|
captureImage(callbackContext);
|
|
667
684
|
return true;
|
|
668
685
|
} catch (Exception e) {
|
|
@@ -670,6 +687,10 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
670
687
|
}
|
|
671
688
|
} else if (action.equals("PickImageFromGallery")) {
|
|
672
689
|
try {
|
|
690
|
+
if(args.length()>0) {
|
|
691
|
+
attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
|
|
692
|
+
galleryAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
|
|
693
|
+
}
|
|
673
694
|
pickImageFromGallery(callbackContext);
|
|
674
695
|
return true;
|
|
675
696
|
} catch (Exception e) {
|
|
@@ -933,13 +954,81 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
933
954
|
callbackContext.success("file://" + mInterfaceUtil.rootDirectory + "/");
|
|
934
955
|
}
|
|
935
956
|
|
|
957
|
+
private void checkLocationPermission(JSONArray args, CallbackContext callbackContext) {
|
|
958
|
+
boolean permissionGranted = true;
|
|
959
|
+
List<String> list;
|
|
960
|
+
try {
|
|
961
|
+
callback = callbackContext;
|
|
962
|
+
Context context = cordova.getActivity().getApplicationContext();
|
|
963
|
+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
|
|
964
|
+
String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
|
|
965
|
+
list = new ArrayList<String>(Arrays.asList(permissions));
|
|
966
|
+
permissions = list.toArray(new String[0]);
|
|
967
|
+
|
|
968
|
+
for (int i = 0; i < permissions.length; i++) {
|
|
969
|
+
if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
|
|
970
|
+
permissionGranted = false;
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
if (!permissionGranted) {
|
|
974
|
+
callback.error("failure");
|
|
975
|
+
} else {
|
|
976
|
+
callback.success("success");
|
|
977
|
+
}
|
|
978
|
+
} else {
|
|
979
|
+
callback.success("success");
|
|
980
|
+
}
|
|
981
|
+
} catch (Exception e) {
|
|
982
|
+
e.printStackTrace();
|
|
983
|
+
}
|
|
984
|
+
}
|
|
985
|
+
private void getLocationPermission(JSONArray args, CallbackContext callbackContext) {
|
|
986
|
+
boolean permissionGranted = true;
|
|
987
|
+
List<String> list;
|
|
988
|
+
try {
|
|
989
|
+
callback = callbackContext;
|
|
990
|
+
Context context = cordova.getActivity().getApplicationContext();
|
|
991
|
+
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.Q) {
|
|
992
|
+
String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
|
|
993
|
+
list = new ArrayList<String>(Arrays.asList(permissions));
|
|
994
|
+
permissions = list.toArray(new String[0]);
|
|
995
|
+
|
|
996
|
+
for (int i = 0; i < permissions.length; i++) {
|
|
997
|
+
if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
|
|
998
|
+
permissionGranted = false;
|
|
999
|
+
}
|
|
1000
|
+
};
|
|
1001
|
+
if (!permissionGranted) {
|
|
1002
|
+
PermissionHelper.requestPermissions(this, 111, permissions);
|
|
1003
|
+
} else {
|
|
1004
|
+
callback.success("success");
|
|
1005
|
+
}
|
|
1006
|
+
} else {
|
|
1007
|
+
callback.success("success");
|
|
1008
|
+
}
|
|
1009
|
+
} catch (Exception e) {
|
|
1010
|
+
e.printStackTrace();
|
|
1011
|
+
}
|
|
1012
|
+
}
|
|
936
1013
|
private void getPermissions(JSONArray args, CallbackContext callbackContext) {
|
|
1014
|
+
boolean permissionGranted = true;
|
|
1015
|
+
List<String> list;
|
|
937
1016
|
try {
|
|
938
1017
|
callback = callbackContext;
|
|
939
1018
|
Context context = cordova.getActivity().getApplicationContext();
|
|
940
1019
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
941
|
-
String[]permissions = args.optJSONObject(0).optString("permissions").split(",");
|
|
942
|
-
if (
|
|
1020
|
+
String[] permissions = args.optJSONObject(0).optString("permissions").split(",");
|
|
1021
|
+
if (Build.VERSION.SDK_INT != Build.VERSION_CODES.Q) {
|
|
1022
|
+
list = new ArrayList<String>(Arrays.asList(permissions));
|
|
1023
|
+
list.remove("android.permission.ACCESS_BACKGROUND_LOCATION");
|
|
1024
|
+
permissions = list.toArray(new String[0]);
|
|
1025
|
+
};
|
|
1026
|
+
for (int i = 0; i < permissions.length; i++) {
|
|
1027
|
+
if (ActivityCompat.checkSelfPermission(context, permissions[i]) != PackageManager.PERMISSION_GRANTED) {
|
|
1028
|
+
permissionGranted = false;
|
|
1029
|
+
}
|
|
1030
|
+
};
|
|
1031
|
+
if (!permissionGranted) {
|
|
943
1032
|
PermissionHelper.requestPermissions(this, 1, permissions);
|
|
944
1033
|
} else {
|
|
945
1034
|
callback.success("success");
|
|
@@ -1180,11 +1269,19 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1180
1269
|
if (file.exists()) {
|
|
1181
1270
|
file.delete();
|
|
1182
1271
|
}
|
|
1272
|
+
attachmentDestPath = "";
|
|
1183
1273
|
callbackContext.success(encodedImage);
|
|
1184
1274
|
} else if (imgSrcType.equals("gallery")) {
|
|
1275
|
+
attachmentDestPath = "";
|
|
1185
1276
|
callbackContext.success(encodedImage);
|
|
1186
1277
|
} else if (imgSrcType.equals("compress")) {
|
|
1187
1278
|
try {
|
|
1279
|
+
if(!destinationPath.equalsIgnoreCase("")){
|
|
1280
|
+
File file = new File(imageSourcePath);
|
|
1281
|
+
if (file.exists()) {
|
|
1282
|
+
file.delete();
|
|
1283
|
+
}
|
|
1284
|
+
}
|
|
1188
1285
|
JSONObject fileProperities = null;
|
|
1189
1286
|
String imgFilePath, fileName, fileExtension = "";
|
|
1190
1287
|
imgFilePath = compressedImageName.substring(0, compressedImageName.lastIndexOf("/"));
|
|
@@ -1199,12 +1296,15 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1199
1296
|
fileProperities.put("fileSize", fileSize);
|
|
1200
1297
|
fileProperities.put("fileExtension", fileExtension);
|
|
1201
1298
|
fileProperities.put("thumbnail", getFileThumbnail(imgFilePath+ "/" +fileName, fileExtension));
|
|
1299
|
+
attachmentDestPath = "";
|
|
1202
1300
|
callback.success(fileProperities);
|
|
1203
1301
|
} catch (Exception e) {
|
|
1302
|
+
attachmentDestPath = "";
|
|
1204
1303
|
callback.error(e.getMessage());
|
|
1205
1304
|
}
|
|
1206
1305
|
}
|
|
1207
1306
|
} catch (Exception e) {
|
|
1307
|
+
attachmentDestPath = "";
|
|
1208
1308
|
callbackContext.error(e.getMessage());
|
|
1209
1309
|
}
|
|
1210
1310
|
} catch (Exception e) {
|
|
@@ -1446,9 +1546,18 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1446
1546
|
if (filePath != null) {
|
|
1447
1547
|
try {
|
|
1448
1548
|
if (fileExtension.equals(".heic")) {
|
|
1449
|
-
|
|
1549
|
+
if(galleryAttachmentInd.equals("true")){
|
|
1550
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress",attachmentDestPath);
|
|
1551
|
+
}else{
|
|
1552
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery","");
|
|
1553
|
+
}
|
|
1554
|
+
|
|
1450
1555
|
} else if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
|
|
1451
|
-
|
|
1556
|
+
if(galleryAttachmentInd.equals("true")){
|
|
1557
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress",attachmentDestPath);
|
|
1558
|
+
}else{
|
|
1559
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery","");
|
|
1560
|
+
}
|
|
1452
1561
|
} else {
|
|
1453
1562
|
callback.error("Only JPEG or PNG file extensions are allowed to attach.");
|
|
1454
1563
|
}
|
|
@@ -1523,6 +1632,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1523
1632
|
fileProperities.put("fileSize", fileSize);
|
|
1524
1633
|
fileProperities.put("fileExtension", extension);
|
|
1525
1634
|
fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
|
|
1635
|
+
attachmentDestPath = "";
|
|
1526
1636
|
callback.success(fileProperities);
|
|
1527
1637
|
}
|
|
1528
1638
|
} else {
|
|
@@ -1546,7 +1656,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1546
1656
|
}
|
|
1547
1657
|
} else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
|
|
1548
1658
|
if (resultCode == RESULT_OK) {
|
|
1549
|
-
|
|
1659
|
+
if(cameraAttachmentInd.equals("true")){
|
|
1660
|
+
convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
|
|
1661
|
+
}else{
|
|
1662
|
+
convertImageTo64BaseString(callback, pictureFilePath, "camera","");
|
|
1663
|
+
}
|
|
1664
|
+
|
|
1550
1665
|
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1551
1666
|
// TODO NO_RESULT or error callback?
|
|
1552
1667
|
File file = new File(pictureFilePath);
|
|
@@ -1721,8 +1836,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1721
1836
|
public void onRequestPermissionResult(int requestCode, String[] permissions, int[] grantResults) {
|
|
1722
1837
|
try {
|
|
1723
1838
|
boolean indicator = true;
|
|
1839
|
+
String failedPermission = "failure";
|
|
1724
1840
|
for (int i = 0; i < grantResults.length; i++) {
|
|
1725
1841
|
if (grantResults[i] != 0) {
|
|
1842
|
+
if (permissions[i].equalsIgnoreCase("android.permission.ACCESS_BACKGROUND_LOCATION")) {
|
|
1843
|
+
failedPermission = "background_location";
|
|
1844
|
+
}
|
|
1726
1845
|
indicator = false;
|
|
1727
1846
|
break;
|
|
1728
1847
|
}
|
|
@@ -1730,7 +1849,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1730
1849
|
if (indicator) {
|
|
1731
1850
|
callback.success("success");
|
|
1732
1851
|
} else {
|
|
1733
|
-
callback.error(
|
|
1852
|
+
callback.error(failedPermission);
|
|
1734
1853
|
}
|
|
1735
1854
|
} catch (Exception e) {
|
|
1736
1855
|
e.printStackTrace();
|
package/src/ios/mInterface.h
CHANGED
|
@@ -40,6 +40,7 @@
|
|
|
40
40
|
UIInterfaceOrientation _lastOrientation;
|
|
41
41
|
}
|
|
42
42
|
@property(strong) NSString* callbackID;
|
|
43
|
+
- (void)GetFCMUtils:(CDVInvokedUrlCommand *)command;
|
|
43
44
|
-(void)GetBase64String:(CDVInvokedUrlCommand *)command;
|
|
44
45
|
- (void)ValidateAppStateInfo;
|
|
45
46
|
-(void)HandleAppStateTimer:(NSString *)status;
|
|
@@ -73,6 +74,7 @@
|
|
|
73
74
|
- (void)OpenFileWithViewer:(CDVInvokedUrlCommand *)command;
|
|
74
75
|
- (void)DeviceInfo:(CDVInvokedUrlCommand*)command;
|
|
75
76
|
-(void)AppVersion:(CDVInvokedUrlCommand*)command;
|
|
77
|
+
-(void)CheckLocationPermission:(CDVInvokedUrlCommand*)command;
|
|
76
78
|
-(void)GetPermissions:(CDVInvokedUrlCommand*)command;
|
|
77
79
|
-(void)RemoveFilesFromDirectory;
|
|
78
80
|
-(void)DespatchQueueMoveToServer;
|
package/src/ios/mInterface.m
CHANGED
|
@@ -10,6 +10,9 @@
|
|
|
10
10
|
#include <sys/types.h>
|
|
11
11
|
#include <sys/sysctl.h>
|
|
12
12
|
#include "TargetConditionals.h"
|
|
13
|
+
#import "OneSignalPush.h"
|
|
14
|
+
#import <OneSignal/OneSignal.h>
|
|
15
|
+
#import <objc/runtime.h>
|
|
13
16
|
|
|
14
17
|
#if defined(__IPHONE_10_0) && __IPHONE_OS_VERSION_MAX_ALLOWED >= __IPHONE_10_0
|
|
15
18
|
@import UserNotifications;
|
|
@@ -26,6 +29,15 @@
|
|
|
26
29
|
@synthesize controller = docController;
|
|
27
30
|
@synthesize callbackID;
|
|
28
31
|
|
|
32
|
+
- (void)GetFCMUtils:(CDVInvokedUrlCommand *)command {
|
|
33
|
+
OSDeviceState *deviceState = [OneSignal getDeviceState];
|
|
34
|
+
NSMutableDictionary * deviceDict = [[NSMutableDictionary alloc] init];
|
|
35
|
+
[deviceDict setValue:deviceState.userId forKey:@"userId"];
|
|
36
|
+
[deviceDict setValue:deviceState.pushToken forKey:@"pushToken"];
|
|
37
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:deviceDict];
|
|
38
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
39
|
+
}
|
|
40
|
+
|
|
29
41
|
-(void)GetBase64String:(CDVInvokedUrlCommand *)command {
|
|
30
42
|
NSMutableDictionary *dict = [[command arguments] objectAtIndex:0];
|
|
31
43
|
NSString *directory = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)[0];
|
|
@@ -955,6 +967,11 @@
|
|
|
955
967
|
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
956
968
|
}
|
|
957
969
|
|
|
970
|
+
-(void)CheckLocationPermission:(CDVInvokedUrlCommand*)command {
|
|
971
|
+
CDVPluginResult *result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
|
|
972
|
+
[self.commandDelegate sendPluginResult:result callbackId:command.callbackId];
|
|
973
|
+
}
|
|
974
|
+
|
|
958
975
|
- (void)SendLocation {
|
|
959
976
|
[self.commandDelegate runInBackground:^{
|
|
960
977
|
@try {
|