cordova-plugin-mserviceinterface-2.0 1.0.61 → 1.0.63
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/backgroundNotification.java +84 -84
- package/src/android/mInterface.java +1413 -1257
- package/src/android/mInterfaceReceiver.java +22 -13
- package/src/android/mInterfaceService.java +45 -37
- package/src/android/mInterfaceUtil.java +60 -33
|
@@ -7,7 +7,6 @@ import android.app.Activity;
|
|
|
7
7
|
import android.app.ActivityManager;
|
|
8
8
|
import android.app.AlertDialog;
|
|
9
9
|
import android.app.ProgressDialog;
|
|
10
|
-
import android.content.ActivityNotFoundException;
|
|
11
10
|
import android.content.ContentResolver;
|
|
12
11
|
import android.content.ContentUris;
|
|
13
12
|
import android.content.Context;
|
|
@@ -137,763 +136,835 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
137
136
|
/* START SERVICE WHEN USER COMES FROM INACTIVE TO ACTIVE STATE IF SERVICE NOT RUNNING */
|
|
138
137
|
@Override
|
|
139
138
|
public void onResume(boolean multitasking) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
if (!
|
|
144
|
-
|
|
139
|
+
try {
|
|
140
|
+
super.onResume(multitasking);
|
|
141
|
+
//To avoid starting service after getting permissions initially.
|
|
142
|
+
if (!mInterfaceUtil.deviceID.equalsIgnoreCase("")) {
|
|
143
|
+
if (!isServiceRunning(mInterfaceService.class) || !isProcessRunning()) {
|
|
144
|
+
cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), mInterfaceService.class));
|
|
145
|
+
}
|
|
145
146
|
}
|
|
147
|
+
} catch (Exception e) {
|
|
148
|
+
System.out.println("onResume: " + e.getMessage());
|
|
146
149
|
}
|
|
147
150
|
}
|
|
148
151
|
|
|
149
152
|
@RequiresApi(api = Build.VERSION_CODES.O)
|
|
150
153
|
@Override
|
|
151
154
|
public boolean execute(final String action, JSONArray args, final CallbackContext callbackContext) throws JSONException {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
mInterfaceUtil.packageName
|
|
155
|
-
|
|
156
|
-
/* START BACKGROUND SERVICE IF NOT RUNNING ALREADY */
|
|
157
|
-
if (action.equals("StartService")) {
|
|
158
|
-
boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
|
|
159
|
-
System.out.println("appInfoUpdated: " + appInfoUpdated);
|
|
160
|
-
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
161
|
-
if (!isServiceRunning(backgroundNotification.class)) {
|
|
162
|
-
cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), backgroundNotification.class));
|
|
163
|
-
}
|
|
164
|
-
if (!isServiceRunning(mInterfaceService.class)) {
|
|
165
|
-
cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), mInterfaceService.class));
|
|
166
|
-
} else {
|
|
167
|
-
System.out.println("Service is already running");
|
|
155
|
+
try {
|
|
156
|
+
mInterfaceUtil.rootDirectory = new File(cordova.getActivity().getExternalFilesDir(""), "");
|
|
157
|
+
if (mInterfaceUtil.packageName.equals("")) {
|
|
158
|
+
mInterfaceUtil.packageName = cordova.getActivity().getApplicationContext().getPackageName().split("\\.")[2];
|
|
168
159
|
}
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
160
|
+
/* START BACKGROUND SERVICE IF NOT RUNNING ALREADY */
|
|
161
|
+
if (action.equals("StartService")) {
|
|
162
|
+
try {
|
|
163
|
+
boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
|
|
164
|
+
System.out.println("appInfoUpdated: " + appInfoUpdated);
|
|
165
|
+
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
166
|
+
if (!isServiceRunning(backgroundNotification.class)) {
|
|
167
|
+
cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), backgroundNotification.class));
|
|
168
|
+
}
|
|
169
|
+
if (!isServiceRunning(mInterfaceService.class)) {
|
|
170
|
+
cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), mInterfaceService.class));
|
|
171
|
+
} else {
|
|
172
|
+
System.out.println("Service is already running");
|
|
173
|
+
}
|
|
174
|
+
callbackContext.success("Success");
|
|
175
|
+
} catch (Exception e) {
|
|
176
|
+
System.out.println("StartService Exception is: " + e.getMessage());
|
|
177
|
+
callbackContext.error(e.getMessage());
|
|
176
178
|
}
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
System.out.println("Exception is: " + e.getMessage());
|
|
187
|
-
callbackContext.error(e.getMessage());
|
|
188
|
-
}
|
|
189
|
-
} else if (action.equals("GetBase64String")) {
|
|
190
|
-
try {
|
|
191
|
-
String imageString = getBase64String(args.getJSONObject(0).optString("filePath"));
|
|
192
|
-
callbackContext.success(imageString);
|
|
193
|
-
} catch (Exception e) {
|
|
194
|
-
System.out.println("Exception is: " + e.getMessage());
|
|
195
|
-
callbackContext.error(e.getMessage());
|
|
196
|
-
}
|
|
197
|
-
} else if (action.equals("GetFCMUtils")) {
|
|
198
|
-
try {
|
|
199
|
-
OSDeviceState device = OneSignal.getDeviceState();
|
|
200
|
-
if (device != null) {
|
|
201
|
-
String userId = device.getUserId();
|
|
202
|
-
//Get device's push token identifier
|
|
203
|
-
String pushToken = device.getPushToken();
|
|
204
|
-
JSONObject progressObj = new JSONObject();
|
|
205
|
-
progressObj.put("userId", userId);
|
|
206
|
-
progressObj.put("pushToken", pushToken);
|
|
207
|
-
callbackContext.success(progressObj);
|
|
208
|
-
} else {
|
|
209
|
-
callbackContext.error("Error occurred");
|
|
179
|
+
} else if (action.equals("showToastWithOptions")) {
|
|
180
|
+
try {
|
|
181
|
+
if (args.getJSONObject(0).optString("duration").equals("long")) {
|
|
182
|
+
Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_LONG).show();
|
|
183
|
+
} else {
|
|
184
|
+
Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_SHORT).show();
|
|
185
|
+
}
|
|
186
|
+
} catch (Exception exception) {
|
|
187
|
+
callbackContext.success(exception.getMessage());
|
|
210
188
|
}
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
callbackContext.error(e.getMessage());
|
|
214
|
-
}
|
|
215
|
-
} else if (action.equals("GetSyncIndicator")) {
|
|
216
|
-
try {
|
|
217
|
-
File newQueueFolder, oldQueueFolder;
|
|
218
|
-
Boolean syncIndication = false;
|
|
219
|
-
BufferedReader readerObj;
|
|
220
|
-
String currentLine, sendData = "";
|
|
221
|
-
URL requestPath;
|
|
222
|
-
HttpURLConnection urlConObj;
|
|
223
|
-
OutputStreamWriter oStreamObj;
|
|
224
|
-
String currentLinedata;
|
|
225
|
-
String client_id = args.getJSONObject(0).optString("client_id");
|
|
226
|
-
String country_code = args.getJSONObject(0).optString("country_code");
|
|
227
|
-
String user_id = args.getJSONObject(0).optString("user_id");
|
|
228
|
-
String client_url = args.getJSONObject(0).optString("client_url");
|
|
229
|
-
String requestUrl = client_url + "/common/components/QueueManager/GetSyncInd.aspx?client_id=" + client_id + "&country_code=" + country_code + "&user_id=" + user_id;
|
|
230
|
-
|
|
189
|
+
} else if (action.equals("CheckLocationAccuracy")) {
|
|
190
|
+
int locationInt;
|
|
231
191
|
try {
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
192
|
+
locationInt = Settings.Secure.getInt(this.cordova.getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);
|
|
193
|
+
callbackContext.success(Integer.toString(locationInt));
|
|
194
|
+
} catch (Settings.SettingNotFoundException e) {
|
|
195
|
+
System.out.println("Exception is: " + e.getMessage());
|
|
196
|
+
callbackContext.error(e.getMessage());
|
|
197
|
+
}
|
|
198
|
+
} else if (action.equals("GetBase64String")) {
|
|
199
|
+
try {
|
|
200
|
+
String imageString = getBase64String(args.getJSONObject(0).optString("filePath"));
|
|
201
|
+
callbackContext.success(imageString);
|
|
202
|
+
} catch (Exception e) {
|
|
203
|
+
System.out.println("Exception is: " + e.getMessage());
|
|
204
|
+
callbackContext.error(e.getMessage());
|
|
205
|
+
}
|
|
206
|
+
} else if (action.equals("GetFCMUtils")) {
|
|
207
|
+
try {
|
|
208
|
+
OSDeviceState device = OneSignal.getDeviceState();
|
|
209
|
+
if (device != null) {
|
|
210
|
+
String userId = device.getUserId();
|
|
211
|
+
//Get device's push token identifier
|
|
212
|
+
String pushToken = device.getPushToken();
|
|
213
|
+
JSONObject progressObj = new JSONObject();
|
|
214
|
+
progressObj.put("userId", userId);
|
|
215
|
+
progressObj.put("pushToken", pushToken);
|
|
216
|
+
callbackContext.success(progressObj);
|
|
238
217
|
} else {
|
|
239
|
-
|
|
218
|
+
callbackContext.error("Error occurred");
|
|
240
219
|
}
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
220
|
+
} catch (Exception e) {
|
|
221
|
+
System.out.println("Exception is: " + e.getMessage());
|
|
222
|
+
callbackContext.error(e.getMessage());
|
|
223
|
+
}
|
|
224
|
+
} else if (action.equals("GetSyncIndicator")) {
|
|
225
|
+
try {
|
|
226
|
+
File newQueueFolder, oldQueueFolder;
|
|
227
|
+
Boolean syncIndication = false;
|
|
228
|
+
BufferedReader readerObj;
|
|
229
|
+
String currentLine, sendData = "";
|
|
230
|
+
URL requestPath;
|
|
231
|
+
HttpURLConnection urlConObj;
|
|
232
|
+
OutputStreamWriter oStreamObj;
|
|
233
|
+
String currentLinedata;
|
|
234
|
+
String client_id = args.getJSONObject(0).optString("client_id");
|
|
235
|
+
String country_code = args.getJSONObject(0).optString("country_code");
|
|
236
|
+
String user_id = args.getJSONObject(0).optString("user_id");
|
|
237
|
+
String client_url = args.getJSONObject(0).optString("client_url");
|
|
238
|
+
String requestUrl = client_url + "/common/components/QueueManager/GetSyncInd.aspx?client_id=" + client_id + "&country_code=" + country_code + "&user_id=" + user_id;
|
|
239
|
+
|
|
240
|
+
try {
|
|
241
|
+
oldQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue");
|
|
242
|
+
newQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + client_id + "/" + country_code + "/database/queue");
|
|
243
|
+
if (oldQueueFolder.exists()) {
|
|
244
|
+
if (oldQueueFolder.listFiles().length == 0) {
|
|
245
|
+
syncIndication = true;
|
|
246
|
+
}
|
|
247
|
+
} else {
|
|
248
|
+
syncIndication = true;
|
|
249
|
+
}
|
|
250
|
+
if (syncIndication) {
|
|
251
|
+
if (newQueueFolder.exists()) {
|
|
252
|
+
if (newQueueFolder.listFiles().length != 0) {
|
|
253
|
+
syncIndication = false;
|
|
254
|
+
}
|
|
245
255
|
}
|
|
246
256
|
}
|
|
257
|
+
if (syncIndication) {
|
|
258
|
+
requestPath = new URL(requestUrl);
|
|
259
|
+
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
260
|
+
urlConObj.setDoOutput(true);
|
|
261
|
+
urlConObj.setRequestMethod("POST");
|
|
262
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/text");
|
|
263
|
+
urlConObj.connect();
|
|
264
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
265
|
+
oStreamObj.write(sendData);
|
|
266
|
+
oStreamObj.flush();
|
|
267
|
+
oStreamObj.close();
|
|
268
|
+
|
|
269
|
+
/* GET RESPONSE FROM SERVER*/
|
|
270
|
+
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
271
|
+
currentLine = readerObj.readLine();
|
|
272
|
+
readerObj.close();
|
|
273
|
+
currentLinedata = currentLine;
|
|
274
|
+
urlConObj.disconnect();
|
|
275
|
+
syncIndication = currentLinedata.equals("true");
|
|
276
|
+
}
|
|
277
|
+
callbackContext.success(String.valueOf(syncIndication));
|
|
278
|
+
} catch (Exception e) {
|
|
279
|
+
callbackContext.error(e.getMessage());
|
|
247
280
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
281
|
+
} catch (Exception e) {
|
|
282
|
+
callbackContext.error(e.getMessage());
|
|
283
|
+
}
|
|
284
|
+
} else if (action.equals("TurnOnAutomaticDateTime")) {
|
|
285
|
+
try {
|
|
286
|
+
Intent intent = new Intent(Settings.ACTION_DATE_SETTINGS);
|
|
287
|
+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
288
|
+
cordova.getActivity().getApplicationContext().startActivity(intent);
|
|
289
|
+
callbackContext.success();
|
|
290
|
+
} catch (Exception e) {
|
|
291
|
+
callbackContext.error(e.getMessage());
|
|
292
|
+
}
|
|
293
|
+
} else if (action.equals("CheckAutomaticTime")) {
|
|
294
|
+
try {
|
|
295
|
+
boolean timeValue = isTimeAutomatic(cordova.getActivity().getApplicationContext());
|
|
296
|
+
String valueString;
|
|
297
|
+
if (timeValue) {
|
|
298
|
+
valueString = "true";
|
|
299
|
+
} else {
|
|
300
|
+
valueString = "false";
|
|
267
301
|
}
|
|
268
|
-
callbackContext.success(
|
|
302
|
+
callbackContext.success(valueString);
|
|
269
303
|
} catch (Exception e) {
|
|
270
|
-
callbackContext.
|
|
304
|
+
callbackContext.error(e.getMessage());
|
|
271
305
|
}
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
if (
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
} else if (action.equals("GetStorageRoot")) {
|
|
312
|
-
getStorageRoot(callbackContext);
|
|
313
|
-
return true;
|
|
314
|
-
} else if (action.equals("RotateScreen")) {
|
|
315
|
-
rotateScreen(args, callbackContext);
|
|
316
|
-
return true;
|
|
317
|
-
} else if (action.equals("UnZip")) {
|
|
318
|
-
unzip(args, callbackContext);
|
|
319
|
-
return true;
|
|
320
|
-
} else if (action.equals("EnableGPSService")) {
|
|
321
|
-
EnableGPSAutomatically(callbackContext);
|
|
322
|
-
} else if ("GoHome".equals(action)) {
|
|
323
|
-
try {
|
|
324
|
-
Intent i = new Intent(Intent.ACTION_MAIN);
|
|
325
|
-
i.addCategory(Intent.CATEGORY_HOME);
|
|
326
|
-
this.cordova.getActivity().startActivity(i);
|
|
327
|
-
} catch (Exception e) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
callbackContext.success();
|
|
331
|
-
return true;
|
|
332
|
-
} else if ("GoBack".equals(action)) {
|
|
333
|
-
try {
|
|
334
|
-
// try to send it back and back to previous app
|
|
335
|
-
boolean sentAppToBackground = this.cordova.getActivity().moveTaskToBack(true);
|
|
336
|
-
// if not possible jump to home
|
|
337
|
-
if (!sentAppToBackground) {
|
|
306
|
+
} else if (action.equals("ServiceCheck")) {
|
|
307
|
+
try {
|
|
308
|
+
String str = "false";
|
|
309
|
+
if (isServiceRunning(mInterfaceService.class)) {
|
|
310
|
+
str = "true";
|
|
311
|
+
System.out.println("service check is: " + str + " " + isServiceRunning(mInterfaceService.class));
|
|
312
|
+
}
|
|
313
|
+
callbackContext.success(str);
|
|
314
|
+
} catch (Exception e) {
|
|
315
|
+
callbackContext.error(e.getMessage());
|
|
316
|
+
}
|
|
317
|
+
} else if (action.equals("GetPermissions")) {
|
|
318
|
+
getPermissions(args, callbackContext);
|
|
319
|
+
return true;
|
|
320
|
+
} else if (action.equals("GetLocationPermission")) {
|
|
321
|
+
getLocationPermission(args, callbackContext);
|
|
322
|
+
return true;
|
|
323
|
+
} else if (action.equals("CheckLocationPermission")) {
|
|
324
|
+
checkLocationPermission(args, callbackContext);
|
|
325
|
+
return true;
|
|
326
|
+
} else if (action.equals("AppVersion")) {
|
|
327
|
+
appVersion(callbackContext);
|
|
328
|
+
return true;
|
|
329
|
+
} else if (action.equals("DeviceInfo")) {
|
|
330
|
+
deviceInfo(callbackContext);
|
|
331
|
+
return true;
|
|
332
|
+
} else if (action.equals("GetStorageRoot")) {
|
|
333
|
+
getStorageRoot(callbackContext);
|
|
334
|
+
return true;
|
|
335
|
+
} else if (action.equals("RotateScreen")) {
|
|
336
|
+
rotateScreen(args, callbackContext);
|
|
337
|
+
return true;
|
|
338
|
+
} else if (action.equals("UnZip")) {
|
|
339
|
+
unzip(args, callbackContext);
|
|
340
|
+
return true;
|
|
341
|
+
} else if (action.equals("EnableGPSService")) {
|
|
342
|
+
EnableGPSAutomatically(callbackContext);
|
|
343
|
+
} else if ("GoHome".equals(action)) {
|
|
344
|
+
try {
|
|
338
345
|
Intent i = new Intent(Intent.ACTION_MAIN);
|
|
339
|
-
i.setAction(Intent.ACTION_MAIN);
|
|
340
346
|
i.addCategory(Intent.CATEGORY_HOME);
|
|
341
347
|
this.cordova.getActivity().startActivity(i);
|
|
348
|
+
callbackContext.success();
|
|
349
|
+
} catch (Exception e) {
|
|
350
|
+
callbackContext.error(e.getMessage());
|
|
342
351
|
}
|
|
343
|
-
}
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
352
|
+
} else if ("GoBack".equals(action)) {
|
|
353
|
+
try {
|
|
354
|
+
// try to send it back and back to previous app
|
|
355
|
+
boolean sentAppToBackground = this.cordova.getActivity().moveTaskToBack(true);
|
|
356
|
+
// if not possible jump to home
|
|
357
|
+
if (!sentAppToBackground) {
|
|
358
|
+
Intent i = new Intent(Intent.ACTION_MAIN);
|
|
359
|
+
i.setAction(Intent.ACTION_MAIN);
|
|
360
|
+
i.addCategory(Intent.CATEGORY_HOME);
|
|
361
|
+
this.cordova.getActivity().startActivity(i);
|
|
362
|
+
}
|
|
363
|
+
callbackContext.success();
|
|
364
|
+
} catch (Exception e) {
|
|
365
|
+
callbackContext.error(e.getMessage());
|
|
366
|
+
}
|
|
367
|
+
} else if (action.equals("Spinner")) {
|
|
368
|
+
if (args.getJSONObject(0).optString("show").equals("true")) {
|
|
369
|
+
final boolean isFixed = true;
|
|
370
|
+
Runnable runnable = new Runnable() {
|
|
371
|
+
public void run() {
|
|
372
|
+
DialogInterface.OnCancelListener onCancelListener = new DialogInterface.OnCancelListener() {
|
|
373
|
+
public void onCancel(DialogInterface dialog) {
|
|
374
|
+
if (!isFixed) {
|
|
375
|
+
while (!mInterface.this.spinnerDialogStack.empty()) {
|
|
376
|
+
mInterface.this.spinnerDialogStack.pop().dismiss();
|
|
377
|
+
callbackContext.success();
|
|
378
|
+
}
|
|
359
379
|
}
|
|
360
380
|
}
|
|
361
|
-
}
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
381
|
+
};
|
|
382
|
+
ProgressDialog dialog;
|
|
383
|
+
if (isFixed) {
|
|
384
|
+
//If there is a progressDialog yet change the text
|
|
385
|
+
if (!mInterface.this.spinnerDialogStack.empty()) {
|
|
386
|
+
dialog = mInterface.this.spinnerDialogStack.peek();
|
|
387
|
+
} else {
|
|
388
|
+
dialog = CallbackProgressDialog.show(cordova.getActivity(), true, false, null, callbackContext);
|
|
389
|
+
mInterface.this.spinnerDialogStack.push(dialog);
|
|
390
|
+
}
|
|
368
391
|
} else {
|
|
369
|
-
|
|
370
|
-
mInterface.this.spinnerDialogStack.
|
|
392
|
+
//If there is a progressDialog yet change the text
|
|
393
|
+
if (!mInterface.this.spinnerDialogStack.empty()) {
|
|
394
|
+
dialog = mInterface.this.spinnerDialogStack.peek();
|
|
395
|
+
} else {
|
|
396
|
+
dialog = ProgressDialog.show(cordova.getActivity(), "", "", true, true, onCancelListener);
|
|
397
|
+
mInterface.this.spinnerDialogStack.push(dialog);
|
|
398
|
+
}
|
|
371
399
|
}
|
|
372
|
-
|
|
373
|
-
|
|
400
|
+
dialog.setContentView(new ProgressBar(cordova.getActivity()));
|
|
401
|
+
}
|
|
402
|
+
};
|
|
403
|
+
this.cordova.getActivity().runOnUiThread(runnable);
|
|
404
|
+
} else {
|
|
405
|
+
Runnable runnable = new Runnable() {
|
|
406
|
+
public void run() {
|
|
374
407
|
if (!mInterface.this.spinnerDialogStack.empty()) {
|
|
375
|
-
|
|
376
|
-
} else {
|
|
377
|
-
dialog = ProgressDialog.show(cordova.getActivity(), "", "", true, true, onCancelListener);
|
|
378
|
-
mInterface.this.spinnerDialogStack.push(dialog);
|
|
408
|
+
mInterface.this.spinnerDialogStack.pop().dismiss();
|
|
379
409
|
}
|
|
380
|
-
}
|
|
381
|
-
dialog.setContentView(new ProgressBar(cordova.getActivity()));
|
|
382
|
-
}
|
|
383
|
-
};
|
|
384
|
-
this.cordova.getActivity().runOnUiThread(runnable);
|
|
385
|
-
} else {
|
|
386
|
-
Runnable runnable = new Runnable() {
|
|
387
|
-
public void run() {
|
|
388
|
-
if (!mInterface.this.spinnerDialogStack.empty()) {
|
|
389
|
-
mInterface.this.spinnerDialogStack.pop().dismiss();
|
|
390
|
-
}
|
|
391
410
|
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
.
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
Boolean syncIndication = false;
|
|
419
|
-
BufferedReader readerObj;
|
|
420
|
-
String currentLine, sendData = "";
|
|
421
|
-
URL requestPath;
|
|
422
|
-
HttpURLConnection urlConObj;
|
|
423
|
-
OutputStreamWriter oStreamObj;
|
|
424
|
-
String currentLinedata;
|
|
425
|
-
String client_id = args.getJSONObject(0).optString("client_id");
|
|
426
|
-
String country_code = args.getJSONObject(0).optString("country_code");
|
|
427
|
-
String user_id = args.getJSONObject(0).optString("user_id");
|
|
428
|
-
String client_url = args.getJSONObject(0).optString("client_url");
|
|
429
|
-
String requestUrl = client_url + "/common/components/QueueManager/GetSyncInd.aspx?client_id=" + client_id + "&country_code=" + country_code + "&user_id=" + user_id;
|
|
411
|
+
}
|
|
412
|
+
};
|
|
413
|
+
this.cordova.getActivity().runOnUiThread(runnable);
|
|
414
|
+
}
|
|
415
|
+
callbackContext.success("success");
|
|
416
|
+
} else if (action.equals("GetPackageName")) {
|
|
417
|
+
try {
|
|
418
|
+
callbackContext.success(cordova.getActivity().getApplicationContext().getPackageName());
|
|
419
|
+
} catch (Exception e) {
|
|
420
|
+
callbackContext.error(e.getMessage());
|
|
421
|
+
}
|
|
422
|
+
} else if (action.equals("GetLocation")) {
|
|
423
|
+
/* SEND CURRENT LOCATION VIA PLUGIN CALLBACK */
|
|
424
|
+
try {
|
|
425
|
+
callbackContext.success(new mInterfaceUtil().getLocation(cordova.getActivity().getApplicationContext()));
|
|
426
|
+
} catch (Exception e) {
|
|
427
|
+
callbackContext.error(e.getMessage());
|
|
428
|
+
}
|
|
429
|
+
} else if (action.equals("CheckLocation")) {
|
|
430
|
+
/* SEND CURRENT LOCATION SETTING STATUS VIA PLUGIN CALLBACK */
|
|
431
|
+
try {
|
|
432
|
+
callbackContext.success(new mInterfaceUtil().checkLocation(cordova.getActivity().getApplicationContext()));
|
|
433
|
+
} catch (Exception e) {
|
|
434
|
+
callbackContext.error(e.getMessage());
|
|
435
|
+
}
|
|
436
|
+
} else if ("GetCurrentLocation".equals(action)) {
|
|
430
437
|
try {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
438
|
+
currentLocationInd = "true";
|
|
439
|
+
callback = callbackContext;
|
|
440
|
+
createLocationRequest1();
|
|
441
|
+
this.mGoogleApiClient1 = new GoogleApiClient.Builder(cordova.getActivity())
|
|
442
|
+
.addConnectionCallbacks(this)
|
|
443
|
+
.addOnConnectionFailedListener(this)
|
|
444
|
+
.addApi(LocationServices.API)
|
|
445
|
+
.build();
|
|
446
|
+
mGoogleApiClient1.connect();
|
|
447
|
+
} catch (Exception e) {
|
|
448
|
+
callbackContext.error(e.getMessage());
|
|
449
|
+
}
|
|
450
|
+
} else if (action.equals("GetSyncIndicator")) {
|
|
451
|
+
try {
|
|
452
|
+
File newQueueFolder, oldQueueFolder;
|
|
453
|
+
Boolean syncIndication = false;
|
|
454
|
+
BufferedReader readerObj;
|
|
455
|
+
String currentLine, sendData = "";
|
|
456
|
+
URL requestPath;
|
|
457
|
+
HttpURLConnection urlConObj;
|
|
458
|
+
OutputStreamWriter oStreamObj;
|
|
459
|
+
String currentLinedata;
|
|
460
|
+
String client_id = args.getJSONObject(0).optString("client_id");
|
|
461
|
+
String country_code = args.getJSONObject(0).optString("country_code");
|
|
462
|
+
String user_id = args.getJSONObject(0).optString("user_id");
|
|
463
|
+
String client_url = args.getJSONObject(0).optString("client_url");
|
|
464
|
+
String requestUrl = client_url + "/common/components/QueueManager/GetSyncInd.aspx?client_id=" + client_id + "&country_code=" + country_code + "&user_id=" + user_id;
|
|
465
|
+
try {
|
|
466
|
+
oldQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue");
|
|
467
|
+
newQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + client_id + "/" + country_code + "/database/queue");
|
|
468
|
+
if (oldQueueFolder.exists()) {
|
|
469
|
+
if (oldQueueFolder.listFiles().length == 0) {
|
|
470
|
+
syncIndication = true;
|
|
471
|
+
}
|
|
472
|
+
} else {
|
|
435
473
|
syncIndication = true;
|
|
436
474
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
if (newQueueFolder.listFiles().length != 0) {
|
|
443
|
-
syncIndication = false;
|
|
475
|
+
if (syncIndication) {
|
|
476
|
+
if (newQueueFolder.exists()) {
|
|
477
|
+
if (newQueueFolder.listFiles().length != 0) {
|
|
478
|
+
syncIndication = false;
|
|
479
|
+
}
|
|
444
480
|
}
|
|
445
481
|
}
|
|
482
|
+
if (syncIndication) {
|
|
483
|
+
requestPath = new URL(requestUrl);
|
|
484
|
+
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
485
|
+
urlConObj.setDoOutput(true);
|
|
486
|
+
urlConObj.setRequestMethod("POST");
|
|
487
|
+
urlConObj.setRequestProperty("CONTENT-TYPE", "application/text");
|
|
488
|
+
urlConObj.connect();
|
|
489
|
+
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
490
|
+
oStreamObj.write(sendData);
|
|
491
|
+
oStreamObj.flush();
|
|
492
|
+
oStreamObj.close();
|
|
493
|
+
|
|
494
|
+
/* GET RESPONSE FROM SERVER*/
|
|
495
|
+
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
496
|
+
currentLine = readerObj.readLine();
|
|
497
|
+
readerObj.close();
|
|
498
|
+
currentLinedata = currentLine;
|
|
499
|
+
urlConObj.disconnect();
|
|
500
|
+
syncIndication = currentLinedata.equals("true");
|
|
501
|
+
}
|
|
502
|
+
callbackContext.success(String.valueOf(syncIndication));
|
|
503
|
+
} catch (Exception e) {
|
|
504
|
+
callbackContext.success(e.getMessage());
|
|
446
505
|
}
|
|
447
|
-
if (syncIndication) {
|
|
448
|
-
requestPath = new URL(requestUrl);
|
|
449
|
-
urlConObj = (HttpURLConnection) requestPath.openConnection();
|
|
450
|
-
urlConObj.setDoOutput(true);
|
|
451
|
-
urlConObj.setRequestMethod("POST");
|
|
452
|
-
urlConObj.setRequestProperty("CONTENT-TYPE", "application/text");
|
|
453
|
-
urlConObj.connect();
|
|
454
|
-
oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
|
|
455
|
-
oStreamObj.write(sendData);
|
|
456
|
-
oStreamObj.flush();
|
|
457
|
-
oStreamObj.close();
|
|
458
|
-
|
|
459
|
-
/* GET RESPONSE FROM SERVER*/
|
|
460
|
-
readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
|
|
461
|
-
currentLine = readerObj.readLine();
|
|
462
|
-
readerObj.close();
|
|
463
|
-
currentLinedata = currentLine;
|
|
464
|
-
urlConObj.disconnect();
|
|
465
|
-
syncIndication = currentLinedata.equals("true");
|
|
466
|
-
}
|
|
467
|
-
callbackContext.success(String.valueOf(syncIndication));
|
|
468
506
|
} catch (Exception e) {
|
|
469
507
|
callbackContext.success(e.getMessage());
|
|
470
508
|
}
|
|
471
|
-
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
for (int index = 0; index < args.length(); index++) {
|
|
507
|
-
inputFileObj = args.getJSONObject(index);
|
|
508
|
-
String filePath = inputFileObj.optString("filePath"),
|
|
509
|
-
serverPath = inputFileObj.optString("serverPath"),
|
|
510
|
-
fileName = inputFileObj.optString("fileName"),
|
|
509
|
+
} else if (action.equals("FileChooser")) {
|
|
510
|
+
try {
|
|
511
|
+
attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
|
|
512
|
+
chooseFile(callbackContext);
|
|
513
|
+
} catch (Exception e) {
|
|
514
|
+
callbackContext.error(e.getMessage());
|
|
515
|
+
}
|
|
516
|
+
return true;
|
|
517
|
+
} else if (action.equals("GetThumbnail")) {
|
|
518
|
+
try {
|
|
519
|
+
String filePath = mInterfaceUtil.rootDirectory + "/" + args.optJSONObject(0).optString("filePath");
|
|
520
|
+
String thumbnail = getFileThumbnail(filePath, args.optJSONObject(0).optString("fileExtension"));
|
|
521
|
+
callback.success(thumbnail);
|
|
522
|
+
} catch (Exception e) {
|
|
523
|
+
callbackContext.error(e.getMessage());
|
|
524
|
+
}
|
|
525
|
+
return true;
|
|
526
|
+
} else if (action.equals("DownloadChatAttachFile")) {
|
|
527
|
+
try {
|
|
528
|
+
String url = args.optJSONObject(0).optString("url"),
|
|
529
|
+
filePath = args.optJSONObject(0).optString("filePath"),
|
|
530
|
+
thumbnailInd = args.optJSONObject(0).optString("thumbnailInd");
|
|
531
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
|
|
532
|
+
pluginResult.setKeepCallback(true);
|
|
533
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
534
|
+
new mInterfaceUtil().DownloadChatAttachment(url, filePath, thumbnailInd, cordova.getActivity().getApplicationContext(), callbackContext, cordova.getActivity());
|
|
535
|
+
} catch (Exception e) {
|
|
536
|
+
callbackContext.error(e.getMessage());
|
|
537
|
+
}
|
|
538
|
+
return true;
|
|
539
|
+
} else if (action.equals("SendChatAttachment")) {
|
|
540
|
+
try {
|
|
541
|
+
String filePath = args.optJSONObject(0).optString("filePath"),
|
|
542
|
+
serverPath = args.optJSONObject(0).optString("serverPath"),
|
|
543
|
+
fileName = args.optJSONObject(0).optString("fileName"),
|
|
511
544
|
attachURL = mInterfaceUtil.clientUrl + "/common/components/msvFileHandler//UploadFiles.aspx?client_id=" + mInterfaceUtil.clientID + "&country_code=" + mInterfaceUtil.countryCode + "&path=" + serverPath;
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
545
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
|
|
546
|
+
pluginResult.setKeepCallback(true);
|
|
547
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
548
|
+
new mInterfaceUtil().sendChatAttachment(filePath, fileName, attachURL, cordova.getActivity(), callbackContext);
|
|
549
|
+
} catch (Exception e) {
|
|
550
|
+
callbackContext.error(e.getMessage());
|
|
551
|
+
}
|
|
552
|
+
return true;
|
|
553
|
+
} else if (action.equals("SendAttachmentToServer")) {
|
|
554
|
+
String statusIndication = "false";
|
|
555
|
+
JSONObject inputFileObj;
|
|
556
|
+
try {
|
|
557
|
+
for (int index = 0; index < args.length(); index++) {
|
|
558
|
+
inputFileObj = args.getJSONObject(index);
|
|
559
|
+
String filePath = inputFileObj.optString("filePath"),
|
|
560
|
+
serverPath = inputFileObj.optString("serverPath"),
|
|
561
|
+
fileName = inputFileObj.optString("fileName"),
|
|
562
|
+
attachURL = mInterfaceUtil.clientUrl + "/common/components/msvFileHandler//UploadFiles.aspx?client_id=" + mInterfaceUtil.clientID + "&country_code=" + mInterfaceUtil.countryCode + "&path=" + serverPath;
|
|
563
|
+
statusIndication = new mInterfaceUtil().sendAttachmentToServer(filePath, fileName, attachURL);
|
|
564
|
+
if (statusIndication.equals("false")) {
|
|
565
|
+
break;
|
|
566
|
+
}
|
|
567
|
+
}
|
|
568
|
+
if (statusIndication.equals("true")) {
|
|
569
|
+
callbackContext.success("success");
|
|
570
|
+
} else {
|
|
571
|
+
callbackContext.error("failure");
|
|
515
572
|
}
|
|
573
|
+
} catch (Exception e) {
|
|
574
|
+
e.printStackTrace();
|
|
575
|
+
callbackContext.error(e.getMessage());
|
|
516
576
|
}
|
|
517
|
-
|
|
577
|
+
return true;
|
|
578
|
+
} else if (action.equals("ReadFile")) {
|
|
579
|
+
try {
|
|
580
|
+
new mInterfaceUtil().readFile(args, callbackContext);
|
|
581
|
+
} catch (Exception e) {
|
|
582
|
+
callbackContext.error(e.getMessage());
|
|
583
|
+
}
|
|
584
|
+
return true;
|
|
585
|
+
} else if (action.equals("DeleteFile")) {
|
|
586
|
+
new mInterfaceUtil().deleteFile(args, callbackContext);
|
|
587
|
+
return true;
|
|
588
|
+
} else if (action.equals("DeleteMultipleFiles")) {
|
|
589
|
+
System.out.println("args.length(): " + args.length());
|
|
590
|
+
for (int index = 0; index < args.length(); index++) {
|
|
591
|
+
String path = args.optString(index);
|
|
592
|
+
new mInterfaceUtil().deleteMultipleFiles(path, callbackContext);
|
|
593
|
+
}
|
|
594
|
+
callbackContext.success();
|
|
595
|
+
return true;
|
|
596
|
+
} else if (action.equals("CreateFile")) {
|
|
597
|
+
new mInterfaceUtil().createFile(args, callbackContext);
|
|
598
|
+
return true;
|
|
599
|
+
} else if (action.equals("ValidateFile")) {
|
|
600
|
+
new mInterfaceUtil().validateFile(args, callbackContext);
|
|
601
|
+
return true;
|
|
602
|
+
} else if (action.equals("CreateDirectory")) {
|
|
603
|
+
new mInterfaceUtil().createDirectory(args, callbackContext);
|
|
604
|
+
return true;
|
|
605
|
+
} else if (action.equals("DeleteDirectory")) {
|
|
606
|
+
new mInterfaceUtil().deleteDirectory(args, callbackContext);
|
|
607
|
+
return true;
|
|
608
|
+
} else if (action.equals("UploadFile")) {
|
|
609
|
+
String filePath = args.getJSONObject(0).optString("filePath");
|
|
610
|
+
String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
|
|
611
|
+
String url = args.getJSONObject(0).optString("url");
|
|
612
|
+
new mInterfaceUtil().sendFilesToServer(filePath, fileName, url);
|
|
613
|
+
return true;
|
|
614
|
+
} else if (action.equals("CopyFile")) {
|
|
615
|
+
arguments = args;
|
|
616
|
+
new mInterfaceUtil().copyFile(callbackContext, arguments);
|
|
617
|
+
} else if (action.equals("CopyAttachmentFile")) {
|
|
618
|
+
arguments = args;
|
|
619
|
+
new mInterfaceUtil().copyAttachmentFile(callbackContext, arguments);
|
|
620
|
+
} else if (action.equals("CopyConfigFile")) {
|
|
621
|
+
arguments = args;
|
|
622
|
+
new mInterfaceUtil().copyConfigFile(callbackContext, arguments);
|
|
623
|
+
} else if (action.equals("GetNewDate")) {
|
|
624
|
+
new mInterfaceUtil().getNewDate(callbackContext);
|
|
625
|
+
} else if (action.equals("RefreshTimeProfile")) {
|
|
626
|
+
JSONObject timeObj = args.getJSONObject(0);
|
|
627
|
+
String date, hour, minute;
|
|
628
|
+
date = timeObj.optString("serverDate");
|
|
629
|
+
hour = timeObj.optString("serverHour");
|
|
630
|
+
minute = timeObj.optString("serverMinute");
|
|
631
|
+
String returnStatus = new mInterfaceUtil().refreshTimeProfile(date, hour, minute);
|
|
632
|
+
if (returnStatus.equals("true")) {
|
|
518
633
|
callbackContext.success("success");
|
|
519
634
|
} else {
|
|
520
635
|
callbackContext.error("failure");
|
|
521
636
|
}
|
|
522
|
-
}
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
new
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
|
|
599
|
-
@Override
|
|
600
|
-
public void onClick(DialogInterface dialog, int which) {
|
|
637
|
+
} else if (action.equals("UpdateChoice")) {
|
|
638
|
+
/* OPEN THE PLAYSTORE MSERVICE APP */
|
|
639
|
+
String appVersion, softwareProductVersion, softwareProductSubVersion;
|
|
640
|
+
JSONObject versionObj;
|
|
641
|
+
AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_HOLO_DARK);
|
|
642
|
+
AlertDialog alertDialog;
|
|
643
|
+
versionObj = args.getJSONObject(0);
|
|
644
|
+
appVersion = versionObj.optString("appVersion");
|
|
645
|
+
softwareProductVersion = versionObj.optString("softwareProductVersion");
|
|
646
|
+
softwareProductSubVersion = versionObj.optString("softwareProductSubVersion");
|
|
647
|
+
builder.setTitle("New Update");
|
|
648
|
+
builder.setMessage("Your mservice version is " + appVersion + ". There is an updated version " + softwareProductVersion + "." + softwareProductSubVersion + " available. Please update.");
|
|
649
|
+
builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
|
|
650
|
+
@Override
|
|
651
|
+
public void onClick(DialogInterface dialog, int which) {
|
|
652
|
+
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + cordova.getActivity().getApplicationContext().getPackageName())));
|
|
653
|
+
callbackContext.error("failure");
|
|
654
|
+
}
|
|
655
|
+
});
|
|
656
|
+
builder.setNegativeButton("Not Now", new DialogInterface.OnClickListener() {
|
|
657
|
+
@Override
|
|
658
|
+
public void onClick(DialogInterface dialog, int which) {
|
|
659
|
+
dialog.cancel();
|
|
660
|
+
callbackContext.success("Success");
|
|
661
|
+
}
|
|
662
|
+
});
|
|
663
|
+
alertDialog = builder.create();
|
|
664
|
+
alertDialog.setCanceledOnTouchOutside(false);
|
|
665
|
+
alertDialog.show();
|
|
666
|
+
alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
|
667
|
+
|
|
668
|
+
@Override
|
|
669
|
+
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
670
|
+
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
671
|
+
dialog.dismiss();
|
|
672
|
+
callbackContext.error("failure");
|
|
673
|
+
}
|
|
674
|
+
return true;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
});
|
|
678
|
+
} else if (action.equals("UpdateConfirm")) {
|
|
679
|
+
/* OPEN THE PLAYSTORE MSERVICE APP */
|
|
680
|
+
String appVersion, softwareProductVersion, softwareProductSubVersion;
|
|
681
|
+
JSONObject versionObj;
|
|
682
|
+
AlertDialog alertDialog;
|
|
683
|
+
AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_HOLO_DARK);
|
|
684
|
+
versionObj = args.getJSONObject(0);
|
|
685
|
+
appVersion = versionObj.optString("appVersion");
|
|
686
|
+
softwareProductVersion = versionObj.optString("softwareProductVersion");
|
|
687
|
+
softwareProductSubVersion = versionObj.optString("softwareProductSubVersion");
|
|
688
|
+
builder.setTitle("New Update");
|
|
689
|
+
builder.setMessage("Your mservice version is " + appVersion + ". Please upgrade the app to " + softwareProductVersion + "." + softwareProductSubVersion + " to proceed.");
|
|
690
|
+
builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
|
|
691
|
+
@Override
|
|
692
|
+
public void onClick(DialogInterface dialog, int which) {
|
|
693
|
+
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + cordova.getActivity().getApplicationContext().getPackageName())));
|
|
694
|
+
callbackContext.error("failure");
|
|
695
|
+
}
|
|
696
|
+
});
|
|
697
|
+
alertDialog = builder.create();
|
|
698
|
+
alertDialog.setCanceledOnTouchOutside(false);
|
|
699
|
+
alertDialog.show();
|
|
700
|
+
alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
|
701
|
+
|
|
702
|
+
@Override
|
|
703
|
+
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
704
|
+
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
705
|
+
dialog.dismiss();
|
|
706
|
+
callbackContext.error("failure");
|
|
707
|
+
}
|
|
708
|
+
return true;
|
|
709
|
+
}
|
|
710
|
+
});
|
|
711
|
+
} else if (action.equals("UpdateNew")) {
|
|
712
|
+
try {
|
|
601
713
|
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + cordova.getActivity().getApplicationContext().getPackageName())));
|
|
602
|
-
callbackContext.
|
|
714
|
+
callbackContext.success("success");
|
|
715
|
+
} catch (Exception e) {
|
|
716
|
+
callbackContext.error(e.getMessage());
|
|
603
717
|
}
|
|
604
|
-
})
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
718
|
+
} else if (action.equals("OpenFileWithViewer")) {
|
|
719
|
+
try {
|
|
720
|
+
Context context = cordova.getActivity().getApplicationContext();
|
|
721
|
+
String filePath = "";
|
|
722
|
+
if (args.optString(0).contains("Android/data/com.selfservit.doubleo/files/")) {
|
|
723
|
+
filePath = mInterfaceUtil.rootDirectory + "/" + (args.optString(0).replace("Android/data/com.selfservit.doubleo/files/", ""));
|
|
724
|
+
} else {
|
|
725
|
+
filePath = mInterfaceUtil.rootDirectory + "/" + args.optString(0);
|
|
726
|
+
}
|
|
727
|
+
File imageFilePath = new File(filePath);
|
|
728
|
+
|
|
729
|
+
Intent intent = new Intent(Intent.ACTION_VIEW);
|
|
730
|
+
Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", imageFilePath);
|
|
731
|
+
intent.setDataAndType(contentUri, getMimeType(filePath, null));
|
|
732
|
+
intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
|
|
733
|
+
cordova.getActivity().startActivity(intent);
|
|
734
|
+
callbackContext.success();
|
|
735
|
+
} catch (Exception e) {
|
|
736
|
+
callbackContext.error(e.getMessage());
|
|
610
737
|
}
|
|
611
|
-
})
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
@Override
|
|
618
|
-
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
619
|
-
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
620
|
-
dialog.dismiss();
|
|
621
|
-
callbackContext.error("failure");
|
|
738
|
+
} else if (action.equals("CaptureImageFromCamera")) {
|
|
739
|
+
try {
|
|
740
|
+
if (args.length() > 0) {
|
|
741
|
+
attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
|
|
742
|
+
cameraAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
|
|
622
743
|
}
|
|
744
|
+
captureImage(callbackContext);
|
|
623
745
|
return true;
|
|
746
|
+
} catch (Exception e) {
|
|
747
|
+
callbackContext.error(e.getMessage());
|
|
624
748
|
}
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
JSONObject versionObj;
|
|
631
|
-
AlertDialog alertDialog;
|
|
632
|
-
AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_HOLO_DARK);
|
|
633
|
-
versionObj = args.getJSONObject(0);
|
|
634
|
-
appVersion = versionObj.optString("appVersion");
|
|
635
|
-
softwareProductVersion = versionObj.optString("softwareProductVersion");
|
|
636
|
-
softwareProductSubVersion = versionObj.optString("softwareProductSubVersion");
|
|
637
|
-
builder.setTitle("New Update");
|
|
638
|
-
builder.setMessage("Your mservice version is " + appVersion + ". Please upgrade the app to " + softwareProductVersion + "." + softwareProductSubVersion + " to proceed.");
|
|
639
|
-
builder.setPositiveButton("Update", new DialogInterface.OnClickListener() {
|
|
640
|
-
@Override
|
|
641
|
-
public void onClick(DialogInterface dialog, int which) {
|
|
642
|
-
cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + cordova.getActivity().getApplicationContext().getPackageName())));
|
|
643
|
-
callbackContext.error("failure");
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
alertDialog = builder.create();
|
|
647
|
-
alertDialog.setCanceledOnTouchOutside(false);
|
|
648
|
-
alertDialog.show();
|
|
649
|
-
alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
|
|
650
|
-
|
|
651
|
-
@Override
|
|
652
|
-
public boolean onKey(DialogInterface dialog, int keyCode, KeyEvent event) {
|
|
653
|
-
if (keyCode == KeyEvent.KEYCODE_BACK) {
|
|
654
|
-
dialog.dismiss();
|
|
655
|
-
callbackContext.error("failure");
|
|
749
|
+
} else if (action.equals("PickImageFromGallery")) {
|
|
750
|
+
try {
|
|
751
|
+
if (args.length() > 0) {
|
|
752
|
+
attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
|
|
753
|
+
galleryAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
|
|
656
754
|
}
|
|
755
|
+
pickImageFromGallery(callbackContext);
|
|
657
756
|
return true;
|
|
757
|
+
} catch (Exception e) {
|
|
758
|
+
callbackContext.error(e.getMessage());
|
|
658
759
|
}
|
|
659
|
-
})
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
if (
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
760
|
+
} else if (action.equals("CaptureFromCamera")) {
|
|
761
|
+
try {
|
|
762
|
+
captureImageLiveCamera(callbackContext);
|
|
763
|
+
return true;
|
|
764
|
+
} catch (Exception e) {
|
|
765
|
+
callbackContext.error(1);
|
|
766
|
+
}
|
|
767
|
+
} else if (action.equals("DeleteSrcFile")) {
|
|
768
|
+
try {
|
|
769
|
+
String filePath = args.getJSONObject(0).optString("filePath");
|
|
770
|
+
String fileName = args.getJSONObject(0).optString("fileName");
|
|
771
|
+
File fullPath = new File(filePath + "/" + fileName);
|
|
772
|
+
if (fullPath.exists()) {
|
|
773
|
+
fullPath.delete();
|
|
774
|
+
callbackContext.success();
|
|
775
|
+
} else {
|
|
776
|
+
callbackContext.error("Expected file is not there to delete..");
|
|
777
|
+
}
|
|
778
|
+
} catch (Exception e) {
|
|
779
|
+
callbackContext.error(1);
|
|
780
|
+
}
|
|
781
|
+
} else if (action.equals("DownloadFile")) {
|
|
782
|
+
try {
|
|
783
|
+
callback = callbackContext;
|
|
784
|
+
final DownloadTask downloadTask = new DownloadTask(cordova.getActivity(), callback);
|
|
785
|
+
downloadTask.execute(args.optJSONObject(0).optString("url"), args.optJSONObject(0).optString("filePath"), args.optJSONObject(0).optString("thumbnailInd"));
|
|
786
|
+
} catch (Exception e) {
|
|
787
|
+
callbackContext.error(e.getMessage());
|
|
687
788
|
}
|
|
688
|
-
captureImage(callbackContext);
|
|
689
789
|
return true;
|
|
690
|
-
}
|
|
691
|
-
|
|
692
|
-
|
|
693
|
-
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
790
|
+
} else if ("QueueProcessor".equals(action)) {
|
|
791
|
+
new mInterfaceUtil().queueProcessor(callbackContext);
|
|
792
|
+
return true;
|
|
793
|
+
} else if (action.equals("ScanQRCode")) {
|
|
794
|
+
try {
|
|
795
|
+
scanQRCode(callbackContext);
|
|
796
|
+
return true;
|
|
797
|
+
} catch (Exception e) {
|
|
798
|
+
callbackContext.error(e.getMessage());
|
|
698
799
|
}
|
|
699
|
-
|
|
800
|
+
} else if (action.equals("ScanBarCode")) {
|
|
801
|
+
try {
|
|
802
|
+
scanBarCode(callbackContext);
|
|
803
|
+
return true;
|
|
804
|
+
} catch (Exception e) {
|
|
805
|
+
callbackContext.error(e.getMessage());
|
|
806
|
+
}
|
|
807
|
+
} else if (action.equals("GetSubDirectoryList")) {
|
|
808
|
+
new mInterfaceUtil().getSubDirectoryList(args, callbackContext);
|
|
700
809
|
return true;
|
|
701
|
-
}
|
|
702
|
-
|
|
703
|
-
}
|
|
704
|
-
} else if (action.equals("CaptureFromCamera")) {
|
|
705
|
-
try {
|
|
706
|
-
captureImageLiveCamera(callbackContext);
|
|
810
|
+
} else if (action.equals("GetFileList")) {
|
|
811
|
+
new mInterfaceUtil().getFileList(args, callbackContext);
|
|
707
812
|
return true;
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
|
|
719
|
-
|
|
720
|
-
callbackContext.error("Expected file is not there to delete..");
|
|
813
|
+
} else if (action.equals("GetAppStateInfo")) {
|
|
814
|
+
try {
|
|
815
|
+
boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
|
|
816
|
+
if (appInfoUpdated) {
|
|
817
|
+
System.out.println("app info updated");
|
|
818
|
+
new mInterfaceUtil().getAppStateInfo(callbackContext, cordova.getActivity().getApplicationContext());
|
|
819
|
+
} else {
|
|
820
|
+
System.out.println("app info not updated");
|
|
821
|
+
callbackContext.success("");
|
|
822
|
+
}
|
|
823
|
+
} catch (Exception e) {
|
|
824
|
+
callbackContext.error(e.getMessage());
|
|
721
825
|
}
|
|
722
|
-
} catch (Exception e) {
|
|
723
|
-
callbackContext.error(1);
|
|
724
|
-
}
|
|
725
|
-
} else if (action.equals("DownloadFile")) {
|
|
726
|
-
callback = callbackContext;
|
|
727
|
-
final DownloadTask downloadTask = new DownloadTask(cordova.getActivity(),callback);
|
|
728
|
-
downloadTask.execute(args.optJSONObject(0).optString("url"), args.optJSONObject(0).optString("filePath"), args.optJSONObject(0).optString("thumbnailInd"));
|
|
729
|
-
return true;
|
|
730
|
-
} else if ("QueueProcessor".equals(action)) {
|
|
731
|
-
new mInterfaceUtil().queueProcessor(callbackContext);
|
|
732
|
-
return true;
|
|
733
|
-
} else if (action.equals("ScanQRCode")) {
|
|
734
|
-
try {
|
|
735
|
-
scanQRCode(callbackContext);
|
|
736
826
|
return true;
|
|
737
|
-
}
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
|
|
742
|
-
|
|
827
|
+
} else if (action.equals("UpdateAppInfo")) {
|
|
828
|
+
try {
|
|
829
|
+
boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
|
|
830
|
+
if (appInfoUpdated) {
|
|
831
|
+
callbackContext.success("success");
|
|
832
|
+
} else {
|
|
833
|
+
callbackContext.error("failed to update app info");
|
|
834
|
+
}
|
|
835
|
+
} catch (Exception e) {
|
|
836
|
+
callbackContext.error(e.getMessage());
|
|
837
|
+
}
|
|
743
838
|
return true;
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
new mInterfaceUtil().moveFile(callbackContext, arguments);
|
|
774
|
-
} else if (action.equals("SendAttachment")) {
|
|
775
|
-
|
|
776
|
-
JSONObject appInfo = args.getJSONObject(0);
|
|
777
|
-
mInterfaceUtil.app_id = appInfo.optString("app_id");
|
|
778
|
-
mInterfaceUtil.platform = appInfo.optString("platform");
|
|
779
|
-
mInterfaceUtil.deviceID = appInfo.optString("device_id");
|
|
780
|
-
new mInterfaceUtil().moveFile(callbackContext, arguments);
|
|
781
|
-
} else if (action.equals("OpenSms")) {
|
|
782
|
-
String contact_number, smsBody;
|
|
783
|
-
Intent smsIntent;
|
|
784
|
-
PluginResult result;
|
|
785
|
-
try {
|
|
786
|
-
contact_number = args.getJSONObject(0).optString("contact_number");
|
|
787
|
-
if (contact_number != null) {
|
|
788
|
-
if (!contact_number.equals("")) {
|
|
789
|
-
if (validateMobileNumber(contact_number)) {
|
|
790
|
-
smsBody = args.getJSONObject(0).optString("msgBody");
|
|
791
|
-
smsIntent = new Intent(Intent.ACTION_VIEW);
|
|
792
|
-
smsIntent.putExtra("sms_body", smsBody);
|
|
793
|
-
smsIntent.setData(Uri.parse("sms:" + contact_number));
|
|
794
|
-
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
795
|
-
cordova.getActivity().getApplicationContext().startActivity(smsIntent);
|
|
839
|
+
} else if (action.equals("MoveFile")) {
|
|
840
|
+
arguments = args;
|
|
841
|
+
new mInterfaceUtil().moveFile(callbackContext, arguments);
|
|
842
|
+
} else if (action.equals("SendAttachment")) {
|
|
843
|
+
|
|
844
|
+
JSONObject appInfo = args.getJSONObject(0);
|
|
845
|
+
mInterfaceUtil.app_id = appInfo.optString("app_id");
|
|
846
|
+
mInterfaceUtil.platform = appInfo.optString("platform");
|
|
847
|
+
mInterfaceUtil.deviceID = appInfo.optString("device_id");
|
|
848
|
+
new mInterfaceUtil().moveFile(callbackContext, arguments);
|
|
849
|
+
} else if (action.equals("OpenSms")) {
|
|
850
|
+
String contact_number, smsBody;
|
|
851
|
+
Intent smsIntent;
|
|
852
|
+
PluginResult result;
|
|
853
|
+
try {
|
|
854
|
+
contact_number = args.getJSONObject(0).optString("contact_number");
|
|
855
|
+
if (contact_number != null) {
|
|
856
|
+
if (!contact_number.equals("")) {
|
|
857
|
+
if (validateMobileNumber(contact_number)) {
|
|
858
|
+
smsBody = args.getJSONObject(0).optString("msgBody");
|
|
859
|
+
smsIntent = new Intent(Intent.ACTION_VIEW);
|
|
860
|
+
smsIntent.putExtra("sms_body", smsBody);
|
|
861
|
+
smsIntent.setData(Uri.parse("sms:" + contact_number));
|
|
862
|
+
smsIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
863
|
+
cordova.getActivity().getApplicationContext().startActivity(smsIntent);
|
|
864
|
+
} else {
|
|
865
|
+
result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_INVALID");
|
|
866
|
+
callback.sendPluginResult(result);
|
|
867
|
+
}
|
|
796
868
|
} else {
|
|
797
|
-
result = new PluginResult(PluginResult.Status.ERROR, "
|
|
869
|
+
result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
|
|
798
870
|
callback.sendPluginResult(result);
|
|
799
871
|
}
|
|
800
872
|
} else {
|
|
801
873
|
result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
|
|
802
874
|
callback.sendPluginResult(result);
|
|
803
875
|
}
|
|
804
|
-
}
|
|
805
|
-
|
|
876
|
+
} catch (JSONException e) {
|
|
877
|
+
e.printStackTrace();
|
|
878
|
+
result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
|
806
879
|
callback.sendPluginResult(result);
|
|
807
880
|
}
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
cordova.getActivity().getApplicationContext().startActivity(intent);
|
|
881
|
+
return true;
|
|
882
|
+
} else if (action.equals("OpenDialPad")) {
|
|
883
|
+
Intent intent;
|
|
884
|
+
PluginResult result;
|
|
885
|
+
try {
|
|
886
|
+
String contact_number = args.getJSONObject(0).optString("contact_number");
|
|
887
|
+
if (contact_number != null) {
|
|
888
|
+
if (!contact_number.equals("")) {
|
|
889
|
+
if (validateMobileNumber(contact_number)) {
|
|
890
|
+
|
|
891
|
+
intent = new Intent(Intent.ACTION_DIAL);
|
|
892
|
+
intent.setData(Uri.parse("tel:" + contact_number));
|
|
893
|
+
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
894
|
+
cordova.getActivity().getApplicationContext().startActivity(intent);
|
|
895
|
+
} else {
|
|
896
|
+
result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_INVALID");
|
|
897
|
+
callback.sendPluginResult(result);
|
|
898
|
+
}
|
|
827
899
|
} else {
|
|
828
|
-
result = new PluginResult(PluginResult.Status.ERROR, "
|
|
900
|
+
result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
|
|
829
901
|
callback.sendPluginResult(result);
|
|
830
902
|
}
|
|
831
903
|
} else {
|
|
832
904
|
result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
|
|
833
905
|
callback.sendPluginResult(result);
|
|
834
906
|
}
|
|
835
|
-
|
|
836
|
-
|
|
907
|
+
|
|
908
|
+
return true;
|
|
909
|
+
} catch (Exception exception) {
|
|
910
|
+
System.out.println(exception.getMessage());
|
|
911
|
+
result = new PluginResult(PluginResult.Status.ERROR, exception.getMessage());
|
|
837
912
|
callback.sendPluginResult(result);
|
|
838
913
|
}
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
emailIntent.setData(Uri.parse(mailto));
|
|
863
|
-
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
864
|
-
cordova.getActivity().getApplicationContext().startActivity(emailIntent);
|
|
914
|
+
} else if (action.equals("OpenEmail")) {
|
|
915
|
+
PluginResult result;
|
|
916
|
+
String toEmail, ccEmail, subject, body, mailto;
|
|
917
|
+
try {
|
|
918
|
+
toEmail = args.getJSONObject(0).optString("toEmail");
|
|
919
|
+
ccEmail = args.getJSONObject(0).optString("ccEmail");
|
|
920
|
+
subject = args.getJSONObject(0).optString("subject");
|
|
921
|
+
body = args.getJSONObject(0).optString("body");
|
|
922
|
+
if (toEmail != null) {
|
|
923
|
+
if (!toEmail.equals("")) {
|
|
924
|
+
if (Patterns.EMAIL_ADDRESS.matcher(toEmail).matches()) {
|
|
925
|
+
mailto = "mailto:" + toEmail +
|
|
926
|
+
"?cc=" + ccEmail +
|
|
927
|
+
"&subject=" + Uri.encode(subject) +
|
|
928
|
+
"&body=" + Uri.encode(body);
|
|
929
|
+
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
|
|
930
|
+
emailIntent.setData(Uri.parse(mailto));
|
|
931
|
+
emailIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
|
932
|
+
cordova.getActivity().getApplicationContext().startActivity(emailIntent);
|
|
933
|
+
} else {
|
|
934
|
+
result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_INVALID");
|
|
935
|
+
callback.sendPluginResult(result);
|
|
936
|
+
}
|
|
865
937
|
} else {
|
|
866
|
-
result = new PluginResult(PluginResult.Status.ERROR, "
|
|
938
|
+
result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_NOT_AVAILABLE");
|
|
867
939
|
callback.sendPluginResult(result);
|
|
868
940
|
}
|
|
869
941
|
} else {
|
|
870
942
|
result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_NOT_AVAILABLE");
|
|
871
943
|
callback.sendPluginResult(result);
|
|
872
944
|
}
|
|
873
|
-
}
|
|
874
|
-
|
|
945
|
+
} catch (Exception e) {
|
|
946
|
+
e.printStackTrace();
|
|
947
|
+
result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
|
875
948
|
callback.sendPluginResult(result);
|
|
876
949
|
}
|
|
877
|
-
} catch (Exception e) {
|
|
878
|
-
e.printStackTrace();
|
|
879
|
-
result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
|
880
|
-
callback.sendPluginResult(result);
|
|
881
|
-
}
|
|
882
950
|
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
951
|
+
} else if (action.equals("OpenAppSettings")) {
|
|
952
|
+
PluginResult result;
|
|
953
|
+
try {
|
|
954
|
+
Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
|
|
955
|
+
Uri uri = Uri.fromParts("package", cordova.getActivity().getPackageName(), null);
|
|
956
|
+
intent.setData(uri);
|
|
957
|
+
cordova.getActivity().startActivity(intent);
|
|
958
|
+
callbackContext.success("success");
|
|
959
|
+
} catch (Exception e) {
|
|
960
|
+
e.printStackTrace();
|
|
961
|
+
result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
|
|
962
|
+
callback.sendPluginResult(result);
|
|
963
|
+
}
|
|
896
964
|
|
|
965
|
+
}
|
|
966
|
+
} catch (JSONException e) {
|
|
967
|
+
System.out.println("execute: " + e.getMessage());
|
|
897
968
|
}
|
|
898
969
|
return true;
|
|
899
970
|
}
|
|
@@ -913,18 +984,27 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
913
984
|
}
|
|
914
985
|
|
|
915
986
|
public static boolean isTimeAutomatic(Context c) {
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
987
|
+
try {
|
|
988
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
|
|
989
|
+
return Settings.Global.getInt(c.getContentResolver(), Settings.Global.AUTO_TIME, 0) == 1;
|
|
990
|
+
} else {
|
|
991
|
+
return Settings.System.getInt(c.getContentResolver(), Settings.System.AUTO_TIME, 0) == 1;
|
|
992
|
+
}
|
|
993
|
+
} catch (Exception e) {
|
|
994
|
+
e.printStackTrace();
|
|
920
995
|
}
|
|
996
|
+
return false;
|
|
921
997
|
}
|
|
922
998
|
|
|
923
999
|
public void createLocationRequest1() {
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
1000
|
+
try {
|
|
1001
|
+
mLocationRequest1 = new LocationRequest();
|
|
1002
|
+
mLocationRequest1.setInterval(INTERVAL);
|
|
1003
|
+
mLocationRequest1.setFastestInterval(FASTEST_INTERVAL);
|
|
1004
|
+
mLocationRequest1.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
|
|
1005
|
+
} catch (Exception e) {
|
|
1006
|
+
e.printStackTrace();
|
|
1007
|
+
}
|
|
928
1008
|
}
|
|
929
1009
|
|
|
930
1010
|
protected void startLocationUpdates1() {
|
|
@@ -934,13 +1014,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
934
1014
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
|
|
935
1015
|
if (ActivityCompat.checkSelfPermission(context1, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED && ActivityCompat.checkSelfPermission(context1, Manifest.permission.ACCESS_COARSE_LOCATION) != PackageManager.PERMISSION_GRANTED) {
|
|
936
1016
|
isPermissionGranted = false;
|
|
937
|
-
}else{
|
|
1017
|
+
} else {
|
|
938
1018
|
isPermissionGranted = true;
|
|
939
1019
|
}
|
|
940
|
-
}else{
|
|
1020
|
+
} else {
|
|
941
1021
|
isPermissionGranted = true;
|
|
942
1022
|
}
|
|
943
|
-
if(isPermissionGranted){
|
|
1023
|
+
if (isPermissionGranted) {
|
|
944
1024
|
PendingResult<Status> pendingResult = LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient1, mLocationRequest1, this);
|
|
945
1025
|
}
|
|
946
1026
|
} catch (Exception e) {
|
|
@@ -949,39 +1029,51 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
949
1029
|
}
|
|
950
1030
|
|
|
951
1031
|
public void scanQRCode(CallbackContext callbackContext) {
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
1032
|
+
try {
|
|
1033
|
+
callback = callbackContext;
|
|
1034
|
+
SCANCODEINT = 118;
|
|
1035
|
+
IntentIntegrator integrator = new IntentIntegrator(this.cordova.getActivity());
|
|
1036
|
+
integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
|
|
1037
|
+
integrator.setPrompt("Scan");
|
|
1038
|
+
integrator.setCameraId(0);
|
|
1039
|
+
integrator.setBeepEnabled(true);
|
|
1040
|
+
integrator.setBarcodeImageEnabled(true);
|
|
1041
|
+
integrator.initiateScan();
|
|
1042
|
+
cordova.setActivityResultCallback(this);
|
|
1043
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
|
|
1044
|
+
pluginResult.setKeepCallback(true);
|
|
1045
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
1046
|
+
} catch (Exception e) {
|
|
1047
|
+
callbackContext.error(e.getMessage());
|
|
1048
|
+
}
|
|
965
1049
|
}
|
|
966
1050
|
|
|
967
1051
|
public void scanBarCode(CallbackContext callbackContext) {
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
1052
|
+
try {
|
|
1053
|
+
callback = callbackContext;
|
|
1054
|
+
SCANCODEINT = 119;
|
|
1055
|
+
IntentIntegrator integrator = new IntentIntegrator(this.cordova.getActivity());
|
|
1056
|
+
integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
|
|
1057
|
+
integrator.setPrompt("Scan");
|
|
1058
|
+
integrator.setCameraId(0);
|
|
1059
|
+
integrator.setBeepEnabled(true);
|
|
1060
|
+
integrator.setBarcodeImageEnabled(true);
|
|
1061
|
+
integrator.initiateScan();
|
|
1062
|
+
cordova.setActivityResultCallback(this);
|
|
1063
|
+
PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
|
|
1064
|
+
pluginResult.setKeepCallback(true);
|
|
1065
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
1066
|
+
} catch (Exception e) {
|
|
1067
|
+
callbackContext.error(e.getMessage());
|
|
1068
|
+
}
|
|
981
1069
|
}
|
|
982
1070
|
|
|
983
1071
|
private void getStorageRoot(CallbackContext callbackContext) {
|
|
984
|
-
|
|
1072
|
+
try {
|
|
1073
|
+
callbackContext.success("file://" + mInterfaceUtil.rootDirectory + "/");
|
|
1074
|
+
} catch (Exception e) {
|
|
1075
|
+
callbackContext.error(e.getMessage());
|
|
1076
|
+
}
|
|
985
1077
|
}
|
|
986
1078
|
|
|
987
1079
|
private void checkLocationPermission(JSONArray args, CallbackContext callbackContext) {
|
|
@@ -1056,7 +1148,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1056
1148
|
list.remove("android.permission.ACCESS_BACKGROUND_LOCATION");
|
|
1057
1149
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
|
|
1058
1150
|
list.remove("android.permission.POST_NOTIFICATIONS");
|
|
1059
|
-
}else{
|
|
1151
|
+
} else {
|
|
1060
1152
|
list.remove("android.permission.WRITE_EXTERNAL_STORAGE");
|
|
1061
1153
|
list.remove("android.permission.READ_EXTERNAL_STORAGE");
|
|
1062
1154
|
}
|
|
@@ -1076,7 +1168,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1076
1168
|
callback.success("success");
|
|
1077
1169
|
}
|
|
1078
1170
|
} catch (Exception e) {
|
|
1079
|
-
e.
|
|
1171
|
+
callback.error(e.getMessage());
|
|
1080
1172
|
}
|
|
1081
1173
|
}
|
|
1082
1174
|
|
|
@@ -1133,33 +1225,27 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1133
1225
|
}
|
|
1134
1226
|
|
|
1135
1227
|
public void pickImageFromGallery(CallbackContext callbackContext) {
|
|
1136
|
-
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
|
|
1144
|
-
|
|
1145
|
-
if (Build.MANUFACTURER.equals("samsung")) {
|
|
1146
|
-
/* SELECT FILE FOR SAMSUNG DEVICES */
|
|
1147
|
-
openFile = new Intent("com.sec.android.app.myfiles.PICK_DATA");
|
|
1148
|
-
openFile.putExtra("CONTENT_TYPE", "*/*");
|
|
1228
|
+
try {
|
|
1229
|
+
Intent openFile,
|
|
1230
|
+
selectFile;
|
|
1231
|
+
PluginResult pluginResult;
|
|
1232
|
+
callback = callbackContext;
|
|
1233
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
|
1234
|
+
// Use the ACTION_OPEN_DOCUMENT intent for Android 13 and higher
|
|
1235
|
+
openFile = new Intent(MediaStore.ACTION_PICK_IMAGES);
|
|
1236
|
+
openFile.setType("image/*");
|
|
1149
1237
|
} else {
|
|
1150
|
-
|
|
1151
|
-
openFile = new Intent(Intent.ACTION_GET_CONTENT);
|
|
1152
|
-
openFile.setType("*/*");
|
|
1153
|
-
openFile.addCategory(Intent.CATEGORY_OPENABLE);
|
|
1238
|
+
openFile = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
|
|
1154
1239
|
openFile.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
|
1155
1240
|
}
|
|
1241
|
+
selectFile = Intent.createChooser(openFile, "Select File");
|
|
1242
|
+
cordova.startActivityForResult(this, selectFile, PICK_IMAGE_FROM_GALLERY);
|
|
1243
|
+
pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
|
|
1244
|
+
pluginResult.setKeepCallback(true);
|
|
1245
|
+
callbackContext.sendPluginResult(pluginResult);
|
|
1246
|
+
} catch (Exception e) {
|
|
1247
|
+
callbackContext.error(e.getMessage());
|
|
1156
1248
|
}
|
|
1157
|
-
|
|
1158
|
-
selectFile = Intent.createChooser(openFile, "Select File");
|
|
1159
|
-
cordova.startActivityForResult(this,selectFile, PICK_IMAGE_FROM_GALLERY);
|
|
1160
|
-
pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
|
|
1161
|
-
pluginResult.setKeepCallback(true);
|
|
1162
|
-
callbackContext.sendPluginResult(pluginResult);
|
|
1163
1249
|
}
|
|
1164
1250
|
|
|
1165
1251
|
private String getMimeType(String path, Uri uri) {
|
|
@@ -1185,33 +1271,43 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1185
1271
|
}
|
|
1186
1272
|
|
|
1187
1273
|
private File createImageFile() throws IOException {
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
storageDir.
|
|
1274
|
+
try {
|
|
1275
|
+
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
1276
|
+
String imageFileName = "JPEG_" + timeStamp + "_";
|
|
1277
|
+
String filePath = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/images";
|
|
1278
|
+
File storageDir = new File(filePath);
|
|
1279
|
+
if (!storageDir.exists()) {
|
|
1280
|
+
storageDir.mkdirs();
|
|
1281
|
+
}
|
|
1282
|
+
File image = File.createTempFile(imageFileName, /* prefix */".jpg", /* suffix */storageDir /* directory */);
|
|
1283
|
+
pictureFilePath = image.getAbsolutePath();
|
|
1284
|
+
return image;
|
|
1285
|
+
} catch (IOException e) {
|
|
1286
|
+
e.printStackTrace();
|
|
1194
1287
|
}
|
|
1195
|
-
|
|
1196
|
-
pictureFilePath = image.getAbsolutePath();
|
|
1197
|
-
return image;
|
|
1288
|
+
return null;
|
|
1198
1289
|
}
|
|
1199
1290
|
|
|
1200
1291
|
public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
inSampleSize
|
|
1292
|
+
try {
|
|
1293
|
+
final int height = options.outHeight;
|
|
1294
|
+
final int width = options.outWidth;
|
|
1295
|
+
int inSampleSize = 1;
|
|
1296
|
+
if (height > reqHeight || width > reqWidth) {
|
|
1297
|
+
final int heightRatio = Math.round((float) height / (float) reqHeight);
|
|
1298
|
+
final int widthRatio = Math.round((float) width / (float) reqWidth);
|
|
1299
|
+
inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
|
|
1300
|
+
}
|
|
1301
|
+
final float totalPixels = width * height;
|
|
1302
|
+
final float totalReqPixelsCap = reqWidth * reqHeight * 2;
|
|
1303
|
+
while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) {
|
|
1304
|
+
inSampleSize++;
|
|
1305
|
+
}
|
|
1306
|
+
return inSampleSize;
|
|
1307
|
+
} catch (Exception e) {
|
|
1308
|
+
e.printStackTrace();
|
|
1213
1309
|
}
|
|
1214
|
-
return
|
|
1310
|
+
return 0;
|
|
1215
1311
|
}
|
|
1216
1312
|
|
|
1217
1313
|
public void convertImageTo64BaseString(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
|
|
@@ -1224,17 +1320,18 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1224
1320
|
Bitmap bitmap;
|
|
1225
1321
|
BitmapFactory.Options options = new BitmapFactory.Options();
|
|
1226
1322
|
options.inJustDecodeBounds = true;
|
|
1227
|
-
|
|
1323
|
+
try {
|
|
1324
|
+
String[] bits = imageSourcePath.split("/");
|
|
1228
1325
|
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1326
|
+
String fileNameToSend = bits[bits.length - 1];
|
|
1327
|
+
if (fileNameToSend.indexOf(".") > 0)
|
|
1328
|
+
fileNameToSend = fileNameToSend.substring(0, fileNameToSend.lastIndexOf("."));
|
|
1329
|
+
|
|
1330
|
+
File fileToCompress = new File(imageSourcePath);
|
|
1331
|
+
String thumbnail = getFileThumbnail(imageSourcePath, "." + imageSourcePath.substring(imageSourcePath.lastIndexOf(".") + 1).toLowerCase());
|
|
1332
|
+
File compressedImageFile;
|
|
1232
1333
|
|
|
1233
|
-
File fileToCompress = new File(imageSourcePath);
|
|
1234
|
-
String thumbnail = getFileThumbnail(imageSourcePath, "." + imageSourcePath.substring(imageSourcePath.lastIndexOf(".") + 1).toLowerCase());
|
|
1235
|
-
File compressedImageFile;
|
|
1236
1334
|
|
|
1237
|
-
try {
|
|
1238
1335
|
compressedImageFile = new Compressor(cordova.getActivity())
|
|
1239
1336
|
.setQuality(15)
|
|
1240
1337
|
.setCompressFormat(Bitmap.CompressFormat.JPEG)
|
|
@@ -1321,7 +1418,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1321
1418
|
callbackContext.error(e.getMessage());
|
|
1322
1419
|
}
|
|
1323
1420
|
|
|
1324
|
-
} catch (
|
|
1421
|
+
} catch (Exception e) {
|
|
1325
1422
|
e.printStackTrace();
|
|
1326
1423
|
}
|
|
1327
1424
|
|
|
@@ -1490,11 +1587,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1490
1587
|
|
|
1491
1588
|
public String getBase64String(String imageSourcePath) {
|
|
1492
1589
|
String resultString = "";
|
|
1493
|
-
String filePath = mInterfaceUtil.rootDirectory + "/" + imageSourcePath;
|
|
1494
|
-
File image = new File(filePath);
|
|
1495
|
-
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
|
|
1496
|
-
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
|
|
1497
1590
|
try {
|
|
1591
|
+
String filePath = mInterfaceUtil.rootDirectory + "/" + imageSourcePath;
|
|
1592
|
+
File image = new File(filePath);
|
|
1593
|
+
BitmapFactory.Options bmOptions = new BitmapFactory.Options();
|
|
1594
|
+
Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
|
|
1595
|
+
|
|
1498
1596
|
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
1499
1597
|
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
|
1500
1598
|
resultString = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
|
|
@@ -1519,17 +1617,22 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1519
1617
|
|
|
1520
1618
|
public Intent getPickImageChooserIntent() {
|
|
1521
1619
|
Intent openFile, selectFile;
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1620
|
+
try {
|
|
1621
|
+
if (Build.MANUFACTURER.equals("samsung")) {
|
|
1622
|
+
openFile = new Intent("com.sec.android.app.myfiles.PICK_DATA");
|
|
1623
|
+
openFile.putExtra("CONTENT_TYPE", "*/*");
|
|
1624
|
+
} else {
|
|
1625
|
+
openFile = new Intent(Intent.ACTION_GET_CONTENT);
|
|
1626
|
+
openFile.setType("*/*");
|
|
1627
|
+
openFile.addCategory(Intent.CATEGORY_OPENABLE);
|
|
1628
|
+
openFile.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
|
|
1629
|
+
}
|
|
1630
|
+
selectFile = Intent.createChooser(openFile, "Select File");
|
|
1631
|
+
return selectFile;
|
|
1632
|
+
} catch (Exception e) {
|
|
1633
|
+
e.printStackTrace();
|
|
1530
1634
|
}
|
|
1531
|
-
|
|
1532
|
-
return selectFile;
|
|
1635
|
+
return null;
|
|
1533
1636
|
}
|
|
1534
1637
|
|
|
1535
1638
|
//App version plugin
|
|
@@ -1537,299 +1640,319 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1537
1640
|
try {
|
|
1538
1641
|
PackageManager packageManager = this.cordova.getActivity().getPackageManager();
|
|
1539
1642
|
JSONObject r = new JSONObject();
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
|
|
1543
|
-
} catch (JSONException e) {
|
|
1544
|
-
e.printStackTrace();
|
|
1545
|
-
}
|
|
1643
|
+
r.put("version", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionName);
|
|
1644
|
+
r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
|
|
1546
1645
|
callbackContext.success(r);
|
|
1547
|
-
} catch (
|
|
1548
|
-
callbackContext.error(
|
|
1646
|
+
} catch (Exception e) {
|
|
1647
|
+
callbackContext.error(e.getMessage());
|
|
1549
1648
|
}
|
|
1550
1649
|
}
|
|
1551
1650
|
|
|
1552
1651
|
//Rotate Screen plugin
|
|
1553
1652
|
public void rotateScreen(JSONArray args, CallbackContext callbackContext) {
|
|
1554
|
-
|
|
1555
|
-
|
|
1556
|
-
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
|
|
1565
|
-
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
1571
|
-
|
|
1572
|
-
|
|
1573
|
-
|
|
1574
|
-
|
|
1575
|
-
|
|
1576
|
-
|
|
1653
|
+
try {
|
|
1654
|
+
String orientation = args.optString(0);
|
|
1655
|
+
String currentOrientation;
|
|
1656
|
+
Activity activity = cordova.getActivity();
|
|
1657
|
+
int orientation1 = activity.getResources().getConfiguration().orientation;
|
|
1658
|
+
if (orientation1 == Configuration.ORIENTATION_LANDSCAPE) {
|
|
1659
|
+
currentOrientation = "landscape";
|
|
1660
|
+
} else {
|
|
1661
|
+
currentOrientation = "portrait";
|
|
1662
|
+
}
|
|
1663
|
+
if (orientation.equals(ANY)) {
|
|
1664
|
+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
|
|
1665
|
+
} else if (orientation.equals(LANDSCAPE_PRIMARY)) {
|
|
1666
|
+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
1667
|
+
} else if (orientation.equals(PORTRAIT_PRIMARY)) {
|
|
1668
|
+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
|
|
1669
|
+
} else if (orientation.equals(LANDSCAPE)) {
|
|
1670
|
+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
|
|
1671
|
+
} else if (orientation.equals(PORTRAIT)) {
|
|
1672
|
+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
|
|
1673
|
+
} else if (orientation.equals(LANDSCAPE_SECONDARY)) {
|
|
1674
|
+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
|
|
1675
|
+
} else if (orientation.equals(PORTRAIT_SECONDARY)) {
|
|
1676
|
+
activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
|
|
1677
|
+
}
|
|
1678
|
+
callbackContext.success(currentOrientation);
|
|
1679
|
+
} catch (Exception e) {
|
|
1680
|
+
callbackContext.success(e.getMessage());
|
|
1577
1681
|
}
|
|
1578
|
-
callbackContext.success(currentOrientation);
|
|
1579
1682
|
}
|
|
1580
1683
|
|
|
1581
|
-
public void deviceInfo(CallbackContext callbackContext)
|
|
1582
|
-
|
|
1583
|
-
|
|
1584
|
-
|
|
1585
|
-
|
|
1586
|
-
|
|
1587
|
-
|
|
1588
|
-
|
|
1589
|
-
|
|
1590
|
-
|
|
1591
|
-
|
|
1592
|
-
|
|
1593
|
-
|
|
1594
|
-
|
|
1595
|
-
|
|
1596
|
-
|
|
1597
|
-
|
|
1598
|
-
|
|
1599
|
-
|
|
1684
|
+
public void deviceInfo(CallbackContext callbackContext) {
|
|
1685
|
+
try {
|
|
1686
|
+
String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), Settings.Secure.ANDROID_ID);
|
|
1687
|
+
JSONObject r = new JSONObject();
|
|
1688
|
+
boolean a = Build.FINGERPRINT.contains("generic") ||
|
|
1689
|
+
Build.PRODUCT.contains("sdk");
|
|
1690
|
+
@SuppressWarnings("deprecation")
|
|
1691
|
+
String sdkversion = Build.VERSION.SDK;
|
|
1692
|
+
r.put("uuid", uuid);
|
|
1693
|
+
r.put("version", Build.VERSION.RELEASE);
|
|
1694
|
+
r.put("platform", ANDROID_PLATFORM);
|
|
1695
|
+
r.put("model", Build.MODEL);
|
|
1696
|
+
r.put("manufacturer", Build.MANUFACTURER);
|
|
1697
|
+
r.put("isVirtual", a);
|
|
1698
|
+
r.put("serial", Build.SERIAL);
|
|
1699
|
+
r.put("timeZone", TimeZone.getDefault());
|
|
1700
|
+
r.put("sdkVersion", sdkversion);
|
|
1701
|
+
r.put("productName", Build.PRODUCT);
|
|
1702
|
+
r.put("applicationName", getApplicationName(cordova.getActivity()));
|
|
1703
|
+
callbackContext.success(r);
|
|
1704
|
+
} catch (Exception e) {
|
|
1705
|
+
callbackContext.error(e.getMessage());
|
|
1706
|
+
}
|
|
1600
1707
|
}
|
|
1601
1708
|
|
|
1602
1709
|
public static String getApplicationName(Context context) {
|
|
1603
|
-
|
|
1604
|
-
|
|
1605
|
-
|
|
1710
|
+
try {
|
|
1711
|
+
ApplicationInfo applicationInfo = context.getApplicationInfo();
|
|
1712
|
+
int stringId = applicationInfo.labelRes;
|
|
1713
|
+
return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
|
|
1714
|
+
} catch (Exception e) {
|
|
1715
|
+
e.printStackTrace();
|
|
1716
|
+
}
|
|
1717
|
+
return "";
|
|
1606
1718
|
}
|
|
1607
1719
|
|
|
1608
1720
|
@Override
|
|
1609
1721
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
|
1610
|
-
|
|
1611
|
-
|
|
1612
|
-
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
if (SCANCODEINT == 118 && callback != null) {
|
|
1625
|
-
if (resultCode == RESULT_OK) {
|
|
1626
|
-
SCANCODEINT = 0;
|
|
1627
|
-
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
|
1628
|
-
callback.success(result.getContents());
|
|
1629
|
-
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1630
|
-
SCANCODEINT = 0;
|
|
1631
|
-
callback.error("canceled");
|
|
1632
|
-
} else {
|
|
1633
|
-
SCANCODEINT = 0;
|
|
1634
|
-
callback.error(resultCode);
|
|
1635
|
-
}
|
|
1636
|
-
} else if (SCANCODEINT == 119 && callback != null) {
|
|
1637
|
-
if (resultCode == RESULT_OK) {
|
|
1638
|
-
SCANCODEINT = 0;
|
|
1639
|
-
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
|
1640
|
-
callback.success(result.getContents());
|
|
1641
|
-
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1642
|
-
SCANCODEINT = 0;
|
|
1643
|
-
callback.error("canceled");
|
|
1644
|
-
} else {
|
|
1645
|
-
SCANCODEINT = 0;
|
|
1646
|
-
callback.error(resultCode);
|
|
1722
|
+
try {
|
|
1723
|
+
switch (requestCode) {
|
|
1724
|
+
case LOCATION_ACCURACY_REQUEST_NEW:
|
|
1725
|
+
switch (resultCode) {
|
|
1726
|
+
case Activity.RESULT_OK:
|
|
1727
|
+
mInterfaceService mInterfaceService = new mInterfaceService();
|
|
1728
|
+
mInterfaceService.startLocationUpdates(cordova.getContext());
|
|
1729
|
+
callback.success();
|
|
1730
|
+
break;
|
|
1731
|
+
case Activity.RESULT_CANCELED:
|
|
1732
|
+
callback.error("oops! you have cancelled...");
|
|
1733
|
+
break;
|
|
1734
|
+
}
|
|
1735
|
+
break;
|
|
1647
1736
|
}
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
|
|
1663
|
-
|
|
1664
|
-
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
|
|
1670
|
-
|
|
1671
|
-
|
|
1737
|
+
if (SCANCODEINT == 118 && callback != null) {
|
|
1738
|
+
if (resultCode == RESULT_OK) {
|
|
1739
|
+
SCANCODEINT = 0;
|
|
1740
|
+
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
|
1741
|
+
callback.success(result.getContents());
|
|
1742
|
+
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1743
|
+
SCANCODEINT = 0;
|
|
1744
|
+
callback.error("canceled");
|
|
1745
|
+
} else {
|
|
1746
|
+
SCANCODEINT = 0;
|
|
1747
|
+
callback.error(resultCode);
|
|
1748
|
+
}
|
|
1749
|
+
} else if (SCANCODEINT == 119 && callback != null) {
|
|
1750
|
+
if (resultCode == RESULT_OK) {
|
|
1751
|
+
SCANCODEINT = 0;
|
|
1752
|
+
IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
|
|
1753
|
+
callback.success(result.getContents());
|
|
1754
|
+
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1755
|
+
SCANCODEINT = 0;
|
|
1756
|
+
callback.error("canceled");
|
|
1757
|
+
} else {
|
|
1758
|
+
SCANCODEINT = 0;
|
|
1759
|
+
callback.error(resultCode);
|
|
1760
|
+
}
|
|
1761
|
+
} else if (requestCode == PICK_IMAGE_FROM_GALLERY && callback != null) {
|
|
1762
|
+
if (resultCode == RESULT_OK) {
|
|
1763
|
+
String fileName = null, getfilePath = null, filePath, fileType, storageDefinition, fileExtension;
|
|
1764
|
+
final String docId, type, id;
|
|
1765
|
+
final String[] split;
|
|
1766
|
+
final String tag, path;
|
|
1767
|
+
final int splitIndex;
|
|
1768
|
+
Cursor cursor;
|
|
1769
|
+
Uri uri = data.getData(); //get uri for selected file
|
|
1770
|
+
fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
|
|
1771
|
+
File getFileName, file;
|
|
1772
|
+
try {
|
|
1773
|
+
//API LEVEL 19 AND ABOVE (TO GET FILEPATH)
|
|
1774
|
+
if (Build.VERSION.SDK_INT >= 19 && !Build.MANUFACTURER.equals("samsung") && DocumentsContract.isDocumentUri(cordova.getActivity(), uri)) {
|
|
1775
|
+
if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { // ExternalStorageProvider
|
|
1776
|
+
docId = DocumentsContract.getDocumentId(uri);
|
|
1777
|
+
split = docId.split(":");
|
|
1778
|
+
type = split[0];
|
|
1779
|
+
if ("primary".equalsIgnoreCase(type)) {
|
|
1780
|
+
getfilePath = mInterfaceUtil.rootDirectory + "/" + split[1];
|
|
1672
1781
|
} else {
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1782
|
+
if (Environment.isExternalStorageRemovable()) {
|
|
1783
|
+
storageDefinition = System.getenv("EXTERNAL_STORAGE");
|
|
1784
|
+
getfilePath = storageDefinition;
|
|
1785
|
+
} else {
|
|
1786
|
+
splitIndex = docId.indexOf(':', 1);
|
|
1787
|
+
tag = docId.substring(0, splitIndex);
|
|
1788
|
+
path = docId.substring(splitIndex + 1);
|
|
1789
|
+
if (new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) != null) {
|
|
1790
|
+
storageDefinition = new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) + "/" + path;
|
|
1791
|
+
file = new File(storageDefinition);
|
|
1792
|
+
if (file.exists() && file.canRead()) {
|
|
1793
|
+
getfilePath = storageDefinition;
|
|
1794
|
+
}
|
|
1681
1795
|
}
|
|
1682
1796
|
}
|
|
1683
1797
|
}
|
|
1684
|
-
}
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
1700
|
-
}
|
|
1701
|
-
final String selection = "_id=?";
|
|
1702
|
-
final String[] selectionArgs = new String[]{
|
|
1703
|
-
split[1]
|
|
1704
|
-
};
|
|
1705
|
-
getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
|
|
1706
|
-
}
|
|
1707
|
-
// *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
|
|
1708
|
-
cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
|
|
1709
|
-
try {
|
|
1710
|
-
if (cursor != null && cursor.moveToFirst()) {
|
|
1711
|
-
int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
1712
|
-
if (displayNameIndex != -1) {
|
|
1713
|
-
fileName = cursor.getString(displayNameIndex);
|
|
1714
|
-
} else {
|
|
1715
|
-
fileName = "";
|
|
1798
|
+
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { // DownloadsProvider
|
|
1799
|
+
id = DocumentsContract.getDocumentId(uri);
|
|
1800
|
+
final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
|
1801
|
+
getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, null, null);
|
|
1802
|
+
} else if ("com.android.providers.media.documents".equals(uri.getAuthority())) { // MediaProvider
|
|
1803
|
+
docId = DocumentsContract.getDocumentId(uri);
|
|
1804
|
+
split = docId.split(":");
|
|
1805
|
+
type = split[0];
|
|
1806
|
+
Uri contentUri = null;
|
|
1807
|
+
if ("image".equals(type)) {
|
|
1808
|
+
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
1809
|
+
} else if ("video".equals(type)) {
|
|
1810
|
+
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
1811
|
+
} else if ("audio".equals(type)) {
|
|
1812
|
+
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
1716
1813
|
}
|
|
1814
|
+
final String selection = "_id=?";
|
|
1815
|
+
final String[] selectionArgs = new String[]{
|
|
1816
|
+
split[1]
|
|
1817
|
+
};
|
|
1818
|
+
getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
|
|
1717
1819
|
}
|
|
1718
|
-
|
|
1719
|
-
cursor.
|
|
1720
|
-
|
|
1721
|
-
|
|
1722
|
-
|
|
1723
|
-
|
|
1724
|
-
|
|
1725
|
-
|
|
1726
|
-
|
|
1727
|
-
|
|
1728
|
-
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
|
|
1732
|
-
fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
|
|
1820
|
+
// *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
|
|
1821
|
+
cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
|
|
1822
|
+
try {
|
|
1823
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
1824
|
+
int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
1825
|
+
if (displayNameIndex != -1) {
|
|
1826
|
+
fileName = cursor.getString(displayNameIndex);
|
|
1827
|
+
} else {
|
|
1828
|
+
fileName = "";
|
|
1829
|
+
}
|
|
1830
|
+
}
|
|
1831
|
+
} finally {
|
|
1832
|
+
cursor.close();
|
|
1733
1833
|
}
|
|
1734
|
-
|
|
1735
|
-
// API LEVEL 19 BELOW AND SAMSUNG (TO GET FILE PROPERTIES OF NORMAL FILES(EX:txt,.pdf,etc..,))
|
|
1834
|
+
// *** API Level 19 below and SAMSUNG (To Get FileProperties of MediaFiles)**** //
|
|
1736
1835
|
} else {
|
|
1737
|
-
|
|
1738
|
-
|
|
1739
|
-
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
if (fileExtension.equals(".heic")) {
|
|
1748
|
-
if (galleryAttachmentInd.equals("true")) {
|
|
1749
|
-
convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
|
|
1750
|
-
} else {
|
|
1751
|
-
convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
|
|
1836
|
+
if (fileType != null) {
|
|
1837
|
+
String[] projection = {
|
|
1838
|
+
MediaStore.Images.Media.DATA,
|
|
1839
|
+
MediaStore.Images.Media.SIZE,
|
|
1840
|
+
MediaStore.Images.Media.DISPLAY_NAME
|
|
1841
|
+
};
|
|
1842
|
+
cursor = cordova.getActivity().getContentResolver().query(uri, projection, null, null, null);
|
|
1843
|
+
if (cursor.moveToFirst()) {
|
|
1844
|
+
getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
|
|
1845
|
+
fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
|
|
1752
1846
|
}
|
|
1847
|
+
cursor.close();
|
|
1848
|
+
// API LEVEL 19 BELOW AND SAMSUNG (TO GET FILE PROPERTIES OF NORMAL FILES(EX:txt,.pdf,etc..,))
|
|
1849
|
+
} else {
|
|
1850
|
+
getfilePath = data.getData().getPath();
|
|
1851
|
+
filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
|
|
1852
|
+
getFileName = new File(getfilePath);
|
|
1853
|
+
fileName = getFileName.getName();
|
|
1854
|
+
}
|
|
1855
|
+
}
|
|
1856
|
+
filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
|
|
1857
|
+
fileExtension = "." + getfilePath.substring(getfilePath.lastIndexOf(".") + 1).toLowerCase();
|
|
1858
|
+
if (filePath != null) {
|
|
1859
|
+
try {
|
|
1860
|
+
if (fileExtension.equals(".heic")) {
|
|
1861
|
+
if (galleryAttachmentInd.equals("true")) {
|
|
1862
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
|
|
1863
|
+
} else {
|
|
1864
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
|
|
1865
|
+
}
|
|
1753
1866
|
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1867
|
+
} else if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
|
|
1868
|
+
if (galleryAttachmentInd.equals("true")) {
|
|
1869
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
|
|
1870
|
+
} else {
|
|
1871
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
|
|
1872
|
+
}
|
|
1757
1873
|
} else {
|
|
1758
|
-
|
|
1874
|
+
callback.error("Only JPEG or PNG file extensions are allowed to attach.");
|
|
1759
1875
|
}
|
|
1760
|
-
}
|
|
1876
|
+
} catch (Exception e) {
|
|
1761
1877
|
callback.error("Only JPEG or PNG file extensions are allowed to attach.");
|
|
1762
1878
|
}
|
|
1763
|
-
}
|
|
1764
|
-
callback.error("
|
|
1879
|
+
} else {
|
|
1880
|
+
callback.error("File path was null");
|
|
1765
1881
|
}
|
|
1766
|
-
}
|
|
1767
|
-
|
|
1768
|
-
}
|
|
1769
|
-
} catch (Exception e) {
|
|
1770
|
-
e.printStackTrace();
|
|
1771
|
-
}
|
|
1772
|
-
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1773
|
-
callback.error("failure");
|
|
1774
|
-
} else {
|
|
1775
|
-
callback.error(resultCode);
|
|
1776
|
-
}
|
|
1777
|
-
} else if (requestCode == NEW_FILE_PICK_REQUEST && callback != null) {
|
|
1778
|
-
try {
|
|
1779
|
-
Uri uri = data.getData();
|
|
1780
|
-
String fileName, extension, filePath;
|
|
1781
|
-
JSONObject fileProperities;
|
|
1782
|
-
Cursor cursor = null;
|
|
1783
|
-
if (uri.getScheme().equals("file")) {
|
|
1784
|
-
fileName = uri.getLastPathSegment();
|
|
1785
|
-
if (fileName.indexOf(".") > 0) {
|
|
1786
|
-
fileName = fileName.substring(0, fileName.lastIndexOf("."));
|
|
1787
|
-
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
1788
|
-
extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
1789
|
-
fileName = fileName + "_" + timeStamp + extension;
|
|
1882
|
+
} catch (Exception e) {
|
|
1883
|
+
e.printStackTrace();
|
|
1790
1884
|
}
|
|
1885
|
+
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1886
|
+
callback.error("failure");
|
|
1791
1887
|
} else {
|
|
1792
|
-
|
|
1793
|
-
|
|
1794
|
-
|
|
1795
|
-
|
|
1796
|
-
|
|
1797
|
-
|
|
1888
|
+
callback.error(resultCode);
|
|
1889
|
+
}
|
|
1890
|
+
} else if (requestCode == NEW_FILE_PICK_REQUEST && callback != null) {
|
|
1891
|
+
try {
|
|
1892
|
+
Uri uri = data.getData();
|
|
1893
|
+
String fileName, extension, filePath;
|
|
1894
|
+
JSONObject fileProperities;
|
|
1895
|
+
Cursor cursor = null;
|
|
1896
|
+
if (uri.getScheme().equals("file")) {
|
|
1897
|
+
fileName = uri.getLastPathSegment();
|
|
1898
|
+
if (fileName.indexOf(".") > 0) {
|
|
1899
|
+
fileName = fileName.substring(0, fileName.lastIndexOf("."));
|
|
1900
|
+
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
1901
|
+
extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
1902
|
+
fileName = fileName + "_" + timeStamp + extension;
|
|
1903
|
+
}
|
|
1904
|
+
} else {
|
|
1905
|
+
try {
|
|
1906
|
+
cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DISPLAY_NAME}, null, null, null);
|
|
1907
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
1908
|
+
int displayNameIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME);
|
|
1909
|
+
if (displayNameIndex != -1) {
|
|
1910
|
+
fileName = cursor.getString(displayNameIndex);
|
|
1911
|
+
} else {
|
|
1912
|
+
fileName = "";
|
|
1913
|
+
}
|
|
1914
|
+
extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
1915
|
+
if (!extension.equals(".jpeg") && !extension.equals(".jpg") && !extension.equals(".png")) {
|
|
1916
|
+
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
|
|
1917
|
+
fileName = fileName.substring(0, fileName.lastIndexOf("."));
|
|
1918
|
+
fileName = fileName + "_" + timeStamp + extension;
|
|
1919
|
+
}
|
|
1920
|
+
|
|
1798
1921
|
} else {
|
|
1799
|
-
fileName =
|
|
1922
|
+
fileName = uri.getLastPathSegment();
|
|
1800
1923
|
}
|
|
1801
|
-
|
|
1802
|
-
if (
|
|
1803
|
-
|
|
1804
|
-
fileName = fileName.substring(0, fileName.lastIndexOf("."));
|
|
1805
|
-
fileName = fileName + "_" + timeStamp + extension;
|
|
1924
|
+
} finally {
|
|
1925
|
+
if (cursor != null) {
|
|
1926
|
+
cursor.close();
|
|
1806
1927
|
}
|
|
1807
|
-
|
|
1808
|
-
} else {
|
|
1809
|
-
fileName = uri.getLastPathSegment();
|
|
1810
|
-
}
|
|
1811
|
-
} finally {
|
|
1812
|
-
if (cursor != null) {
|
|
1813
|
-
cursor.close();
|
|
1814
1928
|
}
|
|
1815
1929
|
}
|
|
1816
|
-
}
|
|
1817
1930
|
|
|
1818
|
-
|
|
1931
|
+
extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
|
|
1819
1932
|
|
|
1820
|
-
|
|
1821
|
-
|
|
1822
|
-
|
|
1823
|
-
|
|
1824
|
-
|
|
1825
|
-
|
|
1826
|
-
|
|
1827
|
-
|
|
1828
|
-
|
|
1829
|
-
convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
|
|
1830
|
-
} else if (mimeType != null) {
|
|
1831
|
-
if (mimeType.contains("image")) {
|
|
1933
|
+
filePath = copyFileFromUri(cordova.getActivity().getApplicationContext(), uri, fileName, attachmentDestPath, callback);
|
|
1934
|
+
File file = new File(filePath);
|
|
1935
|
+
String mimeType = getMimeType(filePath, uri);
|
|
1936
|
+
System.out.println("Mime type is: " + mimeType);
|
|
1937
|
+
double fileSize = file.length();
|
|
1938
|
+
if (filePath != null) {
|
|
1939
|
+
try {
|
|
1940
|
+
if (requestCode == NEW_FILE_PICK_REQUEST) {
|
|
1941
|
+
if (extension.equals(".heic")) {
|
|
1832
1942
|
convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
|
|
1943
|
+
} else if (mimeType != null) {
|
|
1944
|
+
if (mimeType.contains("image")) {
|
|
1945
|
+
convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
|
|
1946
|
+
} else {
|
|
1947
|
+
fileProperities = new JSONObject();
|
|
1948
|
+
fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
|
|
1949
|
+
fileProperities.put("fileName", fileName);
|
|
1950
|
+
fileProperities.put("fileSize", fileSize);
|
|
1951
|
+
fileProperities.put("fileExtension", extension);
|
|
1952
|
+
fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
|
|
1953
|
+
attachmentDestPath = "";
|
|
1954
|
+
callback.success(fileProperities);
|
|
1955
|
+
}
|
|
1833
1956
|
} else {
|
|
1834
1957
|
fileProperities = new JSONObject();
|
|
1835
1958
|
fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
|
|
@@ -1837,207 +1960,200 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
1837
1960
|
fileProperities.put("fileSize", fileSize);
|
|
1838
1961
|
fileProperities.put("fileExtension", extension);
|
|
1839
1962
|
fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
|
|
1840
|
-
attachmentDestPath = "";
|
|
1841
1963
|
callback.success(fileProperities);
|
|
1842
1964
|
}
|
|
1843
|
-
} else {
|
|
1844
|
-
fileProperities = new JSONObject();
|
|
1845
|
-
fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
|
|
1846
|
-
fileProperities.put("fileName", fileName);
|
|
1847
|
-
fileProperities.put("fileSize", fileSize);
|
|
1848
|
-
fileProperities.put("fileExtension", extension);
|
|
1849
|
-
fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
|
|
1850
|
-
callback.success(fileProperities);
|
|
1851
1965
|
}
|
|
1966
|
+
} catch (Exception e) {
|
|
1967
|
+
callback.error(e.getMessage());
|
|
1852
1968
|
}
|
|
1853
|
-
}
|
|
1854
|
-
callback.error(
|
|
1969
|
+
} else {
|
|
1970
|
+
callback.error("Selected file path is null");
|
|
1971
|
+
}
|
|
1972
|
+
} catch (Exception e) {
|
|
1973
|
+
callback.error(e.getMessage());
|
|
1974
|
+
}
|
|
1975
|
+
} else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
|
|
1976
|
+
if (resultCode == RESULT_OK) {
|
|
1977
|
+
if (cameraAttachmentInd.equals("true")) {
|
|
1978
|
+
convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
|
|
1979
|
+
} else {
|
|
1980
|
+
convertImageTo64BaseString(callback, pictureFilePath, "camera", "");
|
|
1981
|
+
}
|
|
1982
|
+
|
|
1983
|
+
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1984
|
+
File file = new File(pictureFilePath);
|
|
1985
|
+
if (file.exists()) {
|
|
1986
|
+
file.delete();
|
|
1855
1987
|
}
|
|
1988
|
+
callback.error("failure");
|
|
1856
1989
|
} else {
|
|
1857
|
-
callback.error(
|
|
1990
|
+
callback.error(resultCode);
|
|
1858
1991
|
}
|
|
1859
|
-
}
|
|
1860
|
-
|
|
1861
|
-
}
|
|
1862
|
-
} else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
|
|
1863
|
-
if (resultCode == RESULT_OK) {
|
|
1864
|
-
if (cameraAttachmentInd.equals("true")) {
|
|
1992
|
+
} else if (requestCode == REQUEST_LIVE_IMAGE_CAPTURE && callback != null) {
|
|
1993
|
+
if (resultCode == RESULT_OK) {
|
|
1865
1994
|
convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
|
|
1995
|
+
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
1996
|
+
File file = new File(pictureFilePath);
|
|
1997
|
+
if (file.exists()) {
|
|
1998
|
+
file.delete();
|
|
1999
|
+
}
|
|
2000
|
+
callback.error("failure");
|
|
1866
2001
|
} else {
|
|
1867
|
-
|
|
2002
|
+
callback.error(resultCode);
|
|
1868
2003
|
}
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
|
|
1872
|
-
|
|
1873
|
-
|
|
1874
|
-
|
|
1875
|
-
|
|
1876
|
-
|
|
1877
|
-
|
|
1878
|
-
|
|
1879
|
-
|
|
1880
|
-
|
|
1881
|
-
|
|
1882
|
-
|
|
1883
|
-
|
|
1884
|
-
|
|
1885
|
-
|
|
1886
|
-
|
|
1887
|
-
|
|
1888
|
-
|
|
1889
|
-
|
|
1890
|
-
|
|
1891
|
-
|
|
1892
|
-
|
|
1893
|
-
|
|
1894
|
-
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
type,
|
|
1902
|
-
id;
|
|
1903
|
-
final String[] split;
|
|
1904
|
-
final String tag,
|
|
1905
|
-
path;
|
|
1906
|
-
final int splitIndex;
|
|
1907
|
-
Cursor cursor;
|
|
1908
|
-
long getSize;
|
|
1909
|
-
JSONObject fileProperities;
|
|
1910
|
-
Uri uri = data.getData(); //get uri for selected file
|
|
1911
|
-
fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
|
|
1912
|
-
File getFileName,
|
|
1913
|
-
file;
|
|
1914
|
-
try {
|
|
1915
|
-
//API LEVEL 19 AND ABOVE (TO GET FILEPATH)
|
|
1916
|
-
if (Build.VERSION.SDK_INT >= 19 && !Build.MANUFACTURER.equals("samsung") && DocumentsContract.isDocumentUri(cordova.getActivity(), uri)) {
|
|
1917
|
-
if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { // ExternalStorageProvider
|
|
1918
|
-
docId = DocumentsContract.getDocumentId(uri);
|
|
1919
|
-
split = docId.split(":");
|
|
1920
|
-
type = split[0];
|
|
1921
|
-
if ("primary".equalsIgnoreCase(type)) {
|
|
1922
|
-
getfilePath = mInterfaceUtil.rootDirectory + "/" + split[1];
|
|
1923
|
-
} else {
|
|
1924
|
-
if (Environment.isExternalStorageRemovable()) {
|
|
1925
|
-
storageDefinition = System.getenv("EXTERNAL_STORAGE");
|
|
1926
|
-
getfilePath = storageDefinition;
|
|
2004
|
+
} else if (requestCode == PICK_FILE_REQUEST && callback != null) {
|
|
2005
|
+
if (resultCode == RESULT_OK) {
|
|
2006
|
+
String fileName = null,
|
|
2007
|
+
getfilePath = null,
|
|
2008
|
+
filePath,
|
|
2009
|
+
fileExtension,
|
|
2010
|
+
fileType,
|
|
2011
|
+
fileSize = null,
|
|
2012
|
+
storageDefinition;
|
|
2013
|
+
final String docId,
|
|
2014
|
+
type,
|
|
2015
|
+
id;
|
|
2016
|
+
final String[] split;
|
|
2017
|
+
final String tag,
|
|
2018
|
+
path;
|
|
2019
|
+
final int splitIndex;
|
|
2020
|
+
Cursor cursor;
|
|
2021
|
+
long getSize;
|
|
2022
|
+
JSONObject fileProperities;
|
|
2023
|
+
Uri uri = data.getData(); //get uri for selected file
|
|
2024
|
+
fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
|
|
2025
|
+
File getFileName,
|
|
2026
|
+
file;
|
|
2027
|
+
try {
|
|
2028
|
+
//API LEVEL 19 AND ABOVE (TO GET FILEPATH)
|
|
2029
|
+
if (Build.VERSION.SDK_INT >= 19 && !Build.MANUFACTURER.equals("samsung") && DocumentsContract.isDocumentUri(cordova.getActivity(), uri)) {
|
|
2030
|
+
if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { // ExternalStorageProvider
|
|
2031
|
+
docId = DocumentsContract.getDocumentId(uri);
|
|
2032
|
+
split = docId.split(":");
|
|
2033
|
+
type = split[0];
|
|
2034
|
+
if ("primary".equalsIgnoreCase(type)) {
|
|
2035
|
+
getfilePath = mInterfaceUtil.rootDirectory + "/" + split[1];
|
|
1927
2036
|
} else {
|
|
1928
|
-
|
|
1929
|
-
|
|
1930
|
-
|
|
1931
|
-
|
|
1932
|
-
|
|
1933
|
-
|
|
1934
|
-
|
|
1935
|
-
|
|
2037
|
+
if (Environment.isExternalStorageRemovable()) {
|
|
2038
|
+
storageDefinition = System.getenv("EXTERNAL_STORAGE");
|
|
2039
|
+
getfilePath = storageDefinition;
|
|
2040
|
+
} else {
|
|
2041
|
+
splitIndex = docId.indexOf(':', 1);
|
|
2042
|
+
tag = docId.substring(0, splitIndex);
|
|
2043
|
+
path = docId.substring(splitIndex + 1);
|
|
2044
|
+
if (new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) != null) {
|
|
2045
|
+
storageDefinition = new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) + "/" + path;
|
|
2046
|
+
file = new File(storageDefinition);
|
|
2047
|
+
if (file.exists() && file.canRead()) {
|
|
2048
|
+
getfilePath = storageDefinition;
|
|
2049
|
+
}
|
|
1936
2050
|
}
|
|
1937
2051
|
}
|
|
1938
2052
|
}
|
|
1939
|
-
}
|
|
1940
|
-
|
|
1941
|
-
|
|
1942
|
-
|
|
1943
|
-
|
|
1944
|
-
|
|
1945
|
-
|
|
1946
|
-
|
|
1947
|
-
|
|
1948
|
-
|
|
1949
|
-
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
1957
|
-
}
|
|
1958
|
-
final String selection = "_id=?";
|
|
1959
|
-
final String[] selectionArgs = new String[]{
|
|
1960
|
-
split[1]
|
|
1961
|
-
};
|
|
1962
|
-
getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
|
|
1963
|
-
}
|
|
1964
|
-
// *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
|
|
1965
|
-
cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
|
|
1966
|
-
try {
|
|
1967
|
-
if (cursor != null && cursor.moveToFirst()) {
|
|
1968
|
-
int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
1969
|
-
if (displayNameIndex != -1) {
|
|
1970
|
-
fileName = cursor.getString(displayNameIndex);
|
|
1971
|
-
} else {
|
|
1972
|
-
fileName = "";
|
|
2053
|
+
} else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { // DownloadsProvider
|
|
2054
|
+
id = DocumentsContract.getDocumentId(uri);
|
|
2055
|
+
final Uri contentUri = ContentUris.withAppendedId(
|
|
2056
|
+
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
|
|
2057
|
+
getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, null, null);
|
|
2058
|
+
|
|
2059
|
+
} else if ("com.android.providers.media.documents".equals(uri.getAuthority())) { // MediaProvider
|
|
2060
|
+
docId = DocumentsContract.getDocumentId(uri);
|
|
2061
|
+
split = docId.split(":");
|
|
2062
|
+
type = split[0];
|
|
2063
|
+
Uri contentUri = null;
|
|
2064
|
+
if ("image".equals(type)) {
|
|
2065
|
+
contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
|
|
2066
|
+
} else if ("video".equals(type)) {
|
|
2067
|
+
contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
|
|
2068
|
+
} else if ("audio".equals(type)) {
|
|
2069
|
+
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
|
|
1973
2070
|
}
|
|
2071
|
+
final String selection = "_id=?";
|
|
2072
|
+
final String[] selectionArgs = new String[]{
|
|
2073
|
+
split[1]
|
|
2074
|
+
};
|
|
2075
|
+
getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
|
|
2076
|
+
}
|
|
2077
|
+
// *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
|
|
2078
|
+
cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
|
|
2079
|
+
try {
|
|
2080
|
+
if (cursor != null && cursor.moveToFirst()) {
|
|
2081
|
+
int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
|
2082
|
+
if (displayNameIndex != -1) {
|
|
2083
|
+
fileName = cursor.getString(displayNameIndex);
|
|
2084
|
+
} else {
|
|
2085
|
+
fileName = "";
|
|
2086
|
+
}
|
|
1974
2087
|
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
2088
|
+
int fileSizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
|
|
2089
|
+
if (!cursor.isNull(fileSizeIndex) && fileSizeIndex != -1) {
|
|
2090
|
+
fileSize = cursor.getString(fileSizeIndex);
|
|
2091
|
+
} else {
|
|
2092
|
+
fileSize = "0";
|
|
2093
|
+
}
|
|
1980
2094
|
}
|
|
2095
|
+
} finally {
|
|
2096
|
+
cursor.close();
|
|
1981
2097
|
}
|
|
1982
|
-
|
|
1983
|
-
cursor.close();
|
|
1984
|
-
}
|
|
1985
|
-
// *** API Level 19 below and SAMSUNG (To Get FileProperties of MediaFiles)**** //
|
|
1986
|
-
} else {
|
|
1987
|
-
if (fileType != null) {
|
|
1988
|
-
String[] projection = {
|
|
1989
|
-
MediaStore.Images.Media.DATA,
|
|
1990
|
-
MediaStore.Images.Media.SIZE,
|
|
1991
|
-
MediaStore.Images.Media.DISPLAY_NAME
|
|
1992
|
-
};
|
|
1993
|
-
cursor = cordova.getActivity().getContentResolver().query(uri, projection, null, null, null);
|
|
1994
|
-
if (cursor.moveToFirst()) {
|
|
1995
|
-
getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
|
|
1996
|
-
fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
|
|
1997
|
-
fileSize = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE));
|
|
1998
|
-
}
|
|
1999
|
-
cursor.close();
|
|
2000
|
-
// API LEVEL 19 BELOW AND SAMSUNG (TO GET FILEPROPERTIES OF NORMAL FILES(EX:txt,.pdf,etc..,))
|
|
2098
|
+
// *** API Level 19 below and SAMSUNG (To Get FileProperties of MediaFiles)**** //
|
|
2001
2099
|
} else {
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
|
|
2013
|
-
|
|
2014
|
-
|
|
2015
|
-
|
|
2016
|
-
convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
|
|
2100
|
+
if (fileType != null) {
|
|
2101
|
+
String[] projection = {
|
|
2102
|
+
MediaStore.Images.Media.DATA,
|
|
2103
|
+
MediaStore.Images.Media.SIZE,
|
|
2104
|
+
MediaStore.Images.Media.DISPLAY_NAME
|
|
2105
|
+
};
|
|
2106
|
+
cursor = cordova.getActivity().getContentResolver().query(uri, projection, null, null, null);
|
|
2107
|
+
if (cursor.moveToFirst()) {
|
|
2108
|
+
getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
|
|
2109
|
+
fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
|
|
2110
|
+
fileSize = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE));
|
|
2111
|
+
}
|
|
2112
|
+
cursor.close();
|
|
2113
|
+
// API LEVEL 19 BELOW AND SAMSUNG (TO GET FILEPROPERTIES OF NORMAL FILES(EX:txt,.pdf,etc..,))
|
|
2017
2114
|
} else {
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2023
|
-
|
|
2115
|
+
getfilePath = data.getData().getPath();
|
|
2116
|
+
filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
|
|
2117
|
+
getFileName = new File(getfilePath);
|
|
2118
|
+
fileName = getFileName.getName();
|
|
2119
|
+
getSize = getFileName.length();
|
|
2120
|
+
fileSize = String.valueOf(getSize);
|
|
2024
2121
|
}
|
|
2025
|
-
} catch (Exception e) {
|
|
2026
|
-
callback.error("Failed to process PICK_FILE_REQUEST");
|
|
2027
2122
|
}
|
|
2028
|
-
|
|
2029
|
-
|
|
2123
|
+
filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
|
|
2124
|
+
fileExtension = "." + getfilePath.substring(getfilePath.lastIndexOf(".") + 1).toLowerCase();
|
|
2125
|
+
// SEND BELOW JSON OBJECT TO PLUGIN CALLBACK
|
|
2126
|
+
if (filePath != null) {
|
|
2127
|
+
try {
|
|
2128
|
+
if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
|
|
2129
|
+
convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
|
|
2130
|
+
} else {
|
|
2131
|
+
fileProperities = new JSONObject();
|
|
2132
|
+
fileProperities.put("filePath", filePath);
|
|
2133
|
+
fileProperities.put("fileName", fileName);
|
|
2134
|
+
fileProperities.put("fileSize", fileSize);
|
|
2135
|
+
fileProperities.put("fileExtension", fileExtension);
|
|
2136
|
+
callback.success(fileProperities);
|
|
2137
|
+
}
|
|
2138
|
+
} catch (Exception e) {
|
|
2139
|
+
callback.error("Failed to process PICK_FILE_REQUEST");
|
|
2140
|
+
}
|
|
2141
|
+
} else {
|
|
2142
|
+
callback.error("File path was null");
|
|
2143
|
+
}
|
|
2144
|
+
} catch (Exception e) {
|
|
2145
|
+
e.printStackTrace();
|
|
2030
2146
|
}
|
|
2031
|
-
}
|
|
2032
|
-
|
|
2147
|
+
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
2148
|
+
callback.error("failure");
|
|
2149
|
+
} else {
|
|
2150
|
+
callback.error(resultCode);
|
|
2033
2151
|
}
|
|
2034
|
-
} else if (resultCode == Activity.RESULT_CANCELED) {
|
|
2035
|
-
callback.error("failure");
|
|
2036
2152
|
} else {
|
|
2037
|
-
callback.error(
|
|
2153
|
+
callback.error("failure");
|
|
2038
2154
|
}
|
|
2039
|
-
}
|
|
2040
|
-
|
|
2155
|
+
} catch (Exception e) {
|
|
2156
|
+
e.printStackTrace();
|
|
2041
2157
|
}
|
|
2042
2158
|
}
|
|
2043
2159
|
|
|
@@ -2103,48 +2219,65 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2103
2219
|
|
|
2104
2220
|
/* CHECKING THE BACKGROUND SERVICE RUNNING OR NOT */
|
|
2105
2221
|
private boolean isServiceRunning(Class<?> serviceClass) {
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2222
|
+
try {
|
|
2223
|
+
ActivityManager manager = (ActivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
|
|
2224
|
+
for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
|
|
2225
|
+
if (serviceClass.getName().equals(service.service.getClassName())) {
|
|
2226
|
+
return true;
|
|
2227
|
+
}
|
|
2110
2228
|
}
|
|
2229
|
+
|
|
2230
|
+
} catch (SecurityException e) {
|
|
2231
|
+
e.printStackTrace();
|
|
2111
2232
|
}
|
|
2112
2233
|
return false;
|
|
2113
2234
|
}
|
|
2114
2235
|
|
|
2115
2236
|
private boolean isProcessRunning() {
|
|
2116
|
-
|
|
2117
|
-
|
|
2118
|
-
|
|
2119
|
-
|
|
2237
|
+
try {
|
|
2238
|
+
ActivityManager manager1 = (ActivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
|
|
2239
|
+
for (ActivityManager.RunningAppProcessInfo processInfo : manager1.getRunningAppProcesses()) {
|
|
2240
|
+
if (processInfo.processName.equals(cordova.getActivity().getPackageName())) {
|
|
2241
|
+
return true;
|
|
2242
|
+
}
|
|
2120
2243
|
}
|
|
2244
|
+
} catch (Exception e) {
|
|
2245
|
+
e.printStackTrace();
|
|
2121
2246
|
}
|
|
2122
2247
|
return false;
|
|
2123
2248
|
}
|
|
2124
2249
|
|
|
2125
2250
|
private void EnableGPSAutomatically(CallbackContext callbackContext) {
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
|
|
2132
|
-
|
|
2133
|
-
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2141
|
-
|
|
2251
|
+
try {
|
|
2252
|
+
callback = callbackContext;
|
|
2253
|
+
createLocationRequest1();
|
|
2254
|
+
mGoogleApiClient1 = new GoogleApiClient.Builder(cordova.getActivity())
|
|
2255
|
+
.addApi(LocationServices.API).addConnectionCallbacks(this)
|
|
2256
|
+
.addOnConnectionFailedListener(this).build();
|
|
2257
|
+
mGoogleApiClient1.connect();
|
|
2258
|
+
LocationRequest locationRequest = LocationRequest.create();
|
|
2259
|
+
locationRequest.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
|
|
2260
|
+
locationRequest.setInterval(30 * 1000);
|
|
2261
|
+
locationRequest.setFastestInterval(5 * 1000);
|
|
2262
|
+
LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
|
|
2263
|
+
.addLocationRequest(locationRequest);
|
|
2264
|
+
builder.setAlwaysShow(true); // this is the key ingredient
|
|
2265
|
+
PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi
|
|
2266
|
+
.checkLocationSettings(mGoogleApiClient1, builder.build());
|
|
2267
|
+
result.setResultCallback(this);
|
|
2268
|
+
} catch (Exception e) {
|
|
2269
|
+
callbackContext.error(e.getMessage());
|
|
2270
|
+
}
|
|
2142
2271
|
}
|
|
2143
2272
|
|
|
2144
2273
|
@Override
|
|
2145
2274
|
public void onConnected(@Nullable Bundle bundle) {
|
|
2146
|
-
|
|
2147
|
-
|
|
2275
|
+
try {
|
|
2276
|
+
if (mGoogleApiClient1.isConnected()) {
|
|
2277
|
+
startLocationUpdates1();
|
|
2278
|
+
}
|
|
2279
|
+
} catch (Exception e) {
|
|
2280
|
+
System.out.println(e.getMessage());
|
|
2148
2281
|
}
|
|
2149
2282
|
}
|
|
2150
2283
|
|
|
@@ -2158,21 +2291,25 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2158
2291
|
|
|
2159
2292
|
@Override
|
|
2160
2293
|
public void onResult(LocationSettingsResult locationSettingsResult) {
|
|
2161
|
-
|
|
2162
|
-
|
|
2163
|
-
|
|
2164
|
-
|
|
2165
|
-
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
2169
|
-
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2294
|
+
try {
|
|
2295
|
+
final Status status = locationSettingsResult.getStatus();
|
|
2296
|
+
switch (status.getStatusCode()) {
|
|
2297
|
+
case LocationSettingsStatusCodes.SUCCESS:
|
|
2298
|
+
break;
|
|
2299
|
+
case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
|
|
2300
|
+
try {
|
|
2301
|
+
this.cordova.setActivityResultCallback(this);
|
|
2302
|
+
status.startResolutionForResult(this.cordova.getActivity(), LOCATION_ACCURACY_REQUEST_NEW);
|
|
2303
|
+
} catch (IntentSender.SendIntentException e) {
|
|
2304
|
+
System.out.println("PendingIntent unable to execute request: ");
|
|
2305
|
+
}
|
|
2306
|
+
break;
|
|
2307
|
+
case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
|
|
2308
|
+
System.out.println("Location settings are inadequate, and cannot be fixed here. Dialog not created.");
|
|
2309
|
+
break;
|
|
2310
|
+
}
|
|
2311
|
+
} catch (Exception e) {
|
|
2312
|
+
System.out.println(e.getMessage());
|
|
2176
2313
|
}
|
|
2177
2314
|
}
|
|
2178
2315
|
|
|
@@ -2261,29 +2398,38 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2261
2398
|
String thumbnail = getFileThumbnail(filePath, extension);
|
|
2262
2399
|
downloadFileCallback.success(thumbnail);
|
|
2263
2400
|
} else {
|
|
2264
|
-
downloadFileCallback.error("Failure
|
|
2401
|
+
downloadFileCallback.error("Failure");
|
|
2265
2402
|
}
|
|
2266
2403
|
} else {
|
|
2267
2404
|
System.out.println("success");
|
|
2268
2405
|
downloadFileCallback.success("");
|
|
2269
2406
|
}
|
|
2270
2407
|
} catch (Exception e) {
|
|
2271
|
-
e.
|
|
2408
|
+
downloadFileCallback.error(e.getMessage());
|
|
2272
2409
|
}
|
|
2273
2410
|
}
|
|
2274
2411
|
}
|
|
2275
2412
|
|
|
2276
2413
|
public static String pathComponent(String filename) {
|
|
2277
|
-
|
|
2278
|
-
|
|
2414
|
+
try {
|
|
2415
|
+
int i = filename.lastIndexOf(File.separator);
|
|
2416
|
+
return (i > -1) ? filename.substring(0, i) : filename;
|
|
2417
|
+
} catch (Exception e) {
|
|
2418
|
+
e.printStackTrace();
|
|
2419
|
+
}
|
|
2420
|
+
return "";
|
|
2279
2421
|
}
|
|
2280
2422
|
|
|
2281
2423
|
private void unzip(final JSONArray args, final CallbackContext callbackContext) {
|
|
2282
|
-
|
|
2283
|
-
|
|
2284
|
-
|
|
2285
|
-
|
|
2286
|
-
|
|
2424
|
+
try {
|
|
2425
|
+
this.cordova.getThreadPool().execute(new Runnable() {
|
|
2426
|
+
public void run() {
|
|
2427
|
+
unzipSync(args, callbackContext);
|
|
2428
|
+
}
|
|
2429
|
+
});
|
|
2430
|
+
} catch (Exception e) {
|
|
2431
|
+
e.printStackTrace();
|
|
2432
|
+
}
|
|
2287
2433
|
}
|
|
2288
2434
|
|
|
2289
2435
|
private void unzipSync(JSONArray args, CallbackContext callbackContext) {
|
|
@@ -2356,7 +2502,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2356
2502
|
else
|
|
2357
2503
|
callbackContext.error("Bad zip file");
|
|
2358
2504
|
} catch (Exception e) {
|
|
2359
|
-
String errorMessage =
|
|
2505
|
+
String errorMessage = e.getMessage();
|
|
2360
2506
|
callbackContext.error(errorMessage);
|
|
2361
2507
|
} finally {
|
|
2362
2508
|
if (inputStream != null) {
|
|
@@ -2386,9 +2532,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2386
2532
|
|
|
2387
2533
|
|
|
2388
2534
|
public boolean isConnected() {
|
|
2389
|
-
|
|
2390
|
-
|
|
2391
|
-
|
|
2535
|
+
try {
|
|
2536
|
+
ConnectivityManager online = (ConnectivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
2537
|
+
NetworkInfo networkInfo = online.getActiveNetworkInfo();
|
|
2538
|
+
return networkInfo != null && networkInfo.isConnected();
|
|
2539
|
+
} catch (Exception e) {
|
|
2540
|
+
e.printStackTrace();
|
|
2541
|
+
}
|
|
2542
|
+
return false;
|
|
2392
2543
|
}
|
|
2393
2544
|
|
|
2394
2545
|
|
|
@@ -2424,8 +2575,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
|
|
|
2424
2575
|
}
|
|
2425
2576
|
|
|
2426
2577
|
public String convertBitmapToString(Bitmap bitmap) {
|
|
2427
|
-
|
|
2428
|
-
|
|
2429
|
-
|
|
2578
|
+
try {
|
|
2579
|
+
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
|
|
2580
|
+
bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
|
|
2581
|
+
return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
|
|
2582
|
+
} catch (Exception e) {
|
|
2583
|
+
e.printStackTrace();
|
|
2584
|
+
}
|
|
2585
|
+
return "";
|
|
2430
2586
|
}
|
|
2431
2587
|
}
|