cordova-plugin-mserviceinterface-2.0 1.0.62 → 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.
@@ -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
- 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));
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
- mInterfaceUtil.rootDirectory = new File(cordova.getActivity().getExternalFilesDir(""), "");
153
- if (mInterfaceUtil.packageName.equals("")) {
154
- mInterfaceUtil.packageName = cordova.getActivity().getApplicationContext().getPackageName().split("\\.")[2];
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
- callbackContext.success("Success");
170
- } else if (action.equals("showToastWithOptions")) {
171
- try {
172
- if (args.getJSONObject(0).optString("duration").equals("long")) {
173
- Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_LONG).show();
174
- } else {
175
- Toast.makeText(cordova.getActivity().getApplicationContext(), args.getJSONObject(0).optString("message"), Toast.LENGTH_SHORT).show();
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
- } catch (Exception exception) {
178
- callbackContext.success("Show Toast having exception");
179
- }
180
- } else if (action.equals("CheckLocationAccuracy")) {
181
- int locationInt;
182
- try {
183
- locationInt = Settings.Secure.getInt(this.cordova.getActivity().getContentResolver(), Settings.Secure.LOCATION_MODE);
184
- callbackContext.success(Integer.toString(locationInt));
185
- } catch (Settings.SettingNotFoundException e) {
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
- } catch (Exception e) {
212
- System.out.println("Exception is: " + e.getMessage());
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
- oldQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue");
233
- newQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + client_id + "/" + country_code + "/database/queue");
234
- if (oldQueueFolder.exists()) {
235
- if (oldQueueFolder.listFiles().length == 0) {
236
- syncIndication = true;
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
- syncIndication = true;
218
+ callbackContext.error("Error occurred");
240
219
  }
241
- if (syncIndication) {
242
- if (newQueueFolder.exists()) {
243
- if (newQueueFolder.listFiles().length != 0) {
244
- syncIndication = false;
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
- if (syncIndication) {
249
- requestPath = new URL(requestUrl);
250
- urlConObj = (HttpURLConnection) requestPath.openConnection();
251
- urlConObj.setDoOutput(true);
252
- urlConObj.setRequestMethod("POST");
253
- urlConObj.setRequestProperty("CONTENT-TYPE", "application/text");
254
- urlConObj.connect();
255
- oStreamObj = new OutputStreamWriter(urlConObj.getOutputStream());
256
- oStreamObj.write(sendData);
257
- oStreamObj.flush();
258
- oStreamObj.close();
259
-
260
- /* GET RESPONSE FROM SERVER*/
261
- readerObj = new BufferedReader(new InputStreamReader(urlConObj.getInputStream()));
262
- currentLine = readerObj.readLine();
263
- readerObj.close();
264
- currentLinedata = currentLine;
265
- urlConObj.disconnect();
266
- syncIndication = currentLinedata.equals("true");
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(String.valueOf(syncIndication));
302
+ callbackContext.success(valueString);
269
303
  } catch (Exception e) {
270
- callbackContext.success(e.getMessage());
304
+ callbackContext.error(e.getMessage());
271
305
  }
272
- } catch (Exception e) {
273
- callbackContext.success(e.getMessage());
274
- }
275
- } else if (action.equals("TurnOnAutomaticDateTime")) {
276
- Intent intent = new Intent(android.provider.Settings.ACTION_DATE_SETTINGS);
277
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
278
- cordova.getActivity().getApplicationContext().startActivity(intent);
279
- callbackContext.success();
280
- } else if (action.equals("CheckAutomaticTime")) {
281
- boolean timeValue = isTimeAutomatic(cordova.getActivity().getApplicationContext());
282
- String valueString;
283
- if (timeValue) {
284
- valueString = "true";
285
- } else {
286
- valueString = "false";
287
- }
288
- callbackContext.success(valueString);
289
- } else if (action.equals("ServiceCheck")) {
290
- String str = "false";
291
- if (isServiceRunning(mInterfaceService.class)) {
292
- str = "true";
293
- System.out.println("service check is: " + str + " " + isServiceRunning(mInterfaceService.class));
294
- }
295
- callbackContext.success(str);
296
- } else if (action.equals("GetPermissions")) {
297
- getPermissions(args, callbackContext);
298
- return true;
299
- } else if (action.equals("GetLocationPermission")) {
300
- getLocationPermission(args, callbackContext);
301
- return true;
302
- } else if (action.equals("CheckLocationPermission")) {
303
- checkLocationPermission(args, callbackContext);
304
- return true;
305
- } else if (action.equals("AppVersion")) {
306
- appVersion(callbackContext);
307
- return true;
308
- } else if (action.equals("DeviceInfo")) {
309
- deviceInfo(callbackContext);
310
- return true;
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
- } catch (Exception e) {
344
- return false;
345
- }
346
- callbackContext.success();
347
- return true;
348
- } else if (action.equals("Spinner")) {
349
- if (args.getJSONObject(0).optString("show").equals("true")) {
350
- final boolean isFixed = true;
351
- Runnable runnable = new Runnable() {
352
- public void run() {
353
- DialogInterface.OnCancelListener onCancelListener = new DialogInterface.OnCancelListener() {
354
- public void onCancel(DialogInterface dialog) {
355
- if (!isFixed) {
356
- while (!mInterface.this.spinnerDialogStack.empty()) {
357
- mInterface.this.spinnerDialogStack.pop().dismiss();
358
- callbackContext.success();
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
- ProgressDialog dialog;
364
- if (isFixed) {
365
- //If there is a progressDialog yet change the text
366
- if (!mInterface.this.spinnerDialogStack.empty()) {
367
- dialog = mInterface.this.spinnerDialogStack.peek();
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
- dialog = CallbackProgressDialog.show(cordova.getActivity(), true, false, null, callbackContext);
370
- mInterface.this.spinnerDialogStack.push(dialog);
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
- } else {
373
- //If there is a progressDialog yet change the text
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
- dialog = mInterface.this.spinnerDialogStack.peek();
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
- this.cordova.getActivity().runOnUiThread(runnable);
395
- }
396
- callbackContext.success("success");
397
- } else if (action.equals("GetPackageName")) {
398
- callbackContext.success(cordova.getActivity().getApplicationContext().getPackageName());
399
- } else if (action.equals("GetLocation")) {
400
- /* SEND CURRENT LOCATION VIA PLUGIN CALLBACK */
401
- callbackContext.success(new mInterfaceUtil().getLocation(cordova.getActivity().getApplicationContext()));
402
- } else if (action.equals("CheckLocation")) {
403
- /* SEND CURRENT LOCATION SETTING STATUS VIA PLUGIN CALLBACK */
404
- callbackContext.success(new mInterfaceUtil().checkLocation(cordova.getActivity().getApplicationContext()));
405
- } else if ("GetCurrentLocation".equals(action)) {
406
- currentLocationInd = "true";
407
- callback = callbackContext;
408
- createLocationRequest1();
409
- this.mGoogleApiClient1 = new GoogleApiClient.Builder(cordova.getActivity())
410
- .addConnectionCallbacks(this)
411
- .addOnConnectionFailedListener(this)
412
- .addApi(LocationServices.API)
413
- .build();
414
- mGoogleApiClient1.connect();
415
- } else if (action.equals("GetSyncIndicator")) {
416
- try {
417
- File newQueueFolder, oldQueueFolder;
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 */
430
424
  try {
431
- oldQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/database/queue");
432
- newQueueFolder = new File(mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + client_id + "/" + country_code + "/database/queue");
433
- if (oldQueueFolder.exists()) {
434
- if (oldQueueFolder.listFiles().length == 0) {
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)) {
437
+ try {
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
- } else {
438
- syncIndication = true;
439
- }
440
- if (syncIndication) {
441
- if (newQueueFolder.exists()) {
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
- } catch (Exception e) {
472
- callbackContext.success(e.getMessage());
473
- }
474
- } else if (action.equals("FileChooser")) {
475
- attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
476
- chooseFile(callbackContext);
477
- return true;
478
- } else if (action.equals("GetThumbnail")) {
479
- String filePath = mInterfaceUtil.rootDirectory + "/" + args.optJSONObject(0).optString("filePath");
480
- String thumbnail = getFileThumbnail(filePath, args.optJSONObject(0).optString("fileExtension"));
481
- callback.success(thumbnail);
482
- return true;
483
- } else if (action.equals("DownloadChatAttachFile")) {
484
- String url = args.optJSONObject(0).optString("url"),
485
- filePath = args.optJSONObject(0).optString("filePath"),
486
- thumbnailInd = args.optJSONObject(0).optString("thumbnailInd");
487
- PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
488
- pluginResult.setKeepCallback(true);
489
- callbackContext.sendPluginResult(pluginResult);
490
- new mInterfaceUtil().DownloadChatAttachment(url, filePath, thumbnailInd, cordova.getActivity().getApplicationContext(), callbackContext, cordova.getActivity());
491
- return true;
492
- } else if (action.equals("SendChatAttachment")) {
493
- String filePath = args.optJSONObject(0).optString("filePath"),
494
- serverPath = args.optJSONObject(0).optString("serverPath"),
495
- fileName = args.optJSONObject(0).optString("fileName"),
496
- attachURL = mInterfaceUtil.clientUrl + "/common/components/msvFileHandler//UploadFiles.aspx?client_id=" + mInterfaceUtil.clientID + "&country_code=" + mInterfaceUtil.countryCode + "&path=" + serverPath;
497
- PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
498
- pluginResult.setKeepCallback(true);
499
- callbackContext.sendPluginResult(pluginResult);
500
- new mInterfaceUtil().sendChatAttachment(filePath, fileName, attachURL, cordova.getActivity(), callbackContext);
501
- return true;
502
- } else if (action.equals("SendAttachmentToServer")) {
503
- String statusIndication = "false";
504
- JSONObject inputFileObj;
505
- try {
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
- statusIndication = new mInterfaceUtil().sendAttachmentToServer(filePath, fileName, attachURL);
513
- if (statusIndication.equals("false")) {
514
- break;
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());
576
+ }
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);
516
593
  }
517
- if (statusIndication.equals("true")) {
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
- } catch (Exception e) {
523
- e.printStackTrace();
524
- callbackContext.error("failure");
525
- }
526
- return true;
527
- } else if (action.equals("ReadFile")) {
528
- try {
529
- new mInterfaceUtil().readFile(args, callbackContext);
530
- } catch (Exception e) {
531
- e.printStackTrace();
532
- }
533
- return true;
534
- } else if (action.equals("DeleteFile")) {
535
- new mInterfaceUtil().deleteFile(args, callbackContext);
536
- return true;
537
- } else if (action.equals("DeleteMultipleFiles")) {
538
- System.out.println("args.length(): " + args.length());
539
- for (int index = 0; index < args.length(); index++) {
540
- String path = args.optString(index);
541
- new mInterfaceUtil().deleteMultipleFiles(path, callbackContext);
542
- }
543
- callbackContext.success();
544
- return true;
545
- } else if (action.equals("CreateFile")) {
546
- new mInterfaceUtil().createFile(args, callbackContext);
547
- return true;
548
- } else if (action.equals("ValidateFile")) {
549
- new mInterfaceUtil().validateFile(args, callbackContext);
550
- return true;
551
- } else if (action.equals("CreateDirectory")) {
552
- new mInterfaceUtil().createDirectory(args, callbackContext);
553
- return true;
554
- } else if (action.equals("DeleteDirectory")) {
555
- new mInterfaceUtil().deleteDirectory(args, callbackContext);
556
- return true;
557
- } else if (action.equals("UploadFile")) {
558
- String filePath = args.getJSONObject(0).optString("filePath");
559
- String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
560
- String url = args.getJSONObject(0).optString("url");
561
- new mInterfaceUtil().sendFilesToServer(filePath, fileName, url);
562
- return true;
563
- } else if (action.equals("CopyFile")) {
564
- arguments = args;
565
- new mInterfaceUtil().copyFile(callbackContext, arguments);
566
- } else if (action.equals("CopyAttachmentFile")) {
567
- arguments = args;
568
- new mInterfaceUtil().copyAttachmentFile(callbackContext, arguments);
569
- } else if (action.equals("CopyConfigFile")) {
570
- arguments = args;
571
- new mInterfaceUtil().copyConfigFile(callbackContext, arguments);
572
- } else if (action.equals("GetNewDate")) {
573
- new mInterfaceUtil().getNewDate(callbackContext);
574
- } else if (action.equals("RefreshTimeProfile")) {
575
- JSONObject timeObj = args.getJSONObject(0);
576
- String date, hour, minute;
577
- date = timeObj.optString("serverDate");
578
- hour = timeObj.optString("serverHour");
579
- minute = timeObj.optString("serverMinute");
580
- String returnStatus = new mInterfaceUtil().refreshTimeProfile(date, hour, minute);
581
- if (returnStatus.equals("true")) {
582
- callbackContext.success("success");
583
- } else {
584
- callbackContext.error("failure");
585
- }
586
- } else if (action.equals("UpdateChoice")) {
587
- /* OPEN THE PLAYSTORE MSERVICE APP */
588
- String appVersion, softwareProductVersion, softwareProductSubVersion;
589
- JSONObject versionObj;
590
- AlertDialog.Builder builder = new AlertDialog.Builder(cordova.getActivity(), AlertDialog.THEME_HOLO_DARK);
591
- AlertDialog alertDialog;
592
- versionObj = args.getJSONObject(0);
593
- appVersion = versionObj.optString("appVersion");
594
- softwareProductVersion = versionObj.optString("softwareProductVersion");
595
- softwareProductSubVersion = versionObj.optString("softwareProductSubVersion");
596
- builder.setTitle("New Update");
597
- builder.setMessage("Your mservice version is " + appVersion + ". There is an updated version " + softwareProductVersion + "." + softwareProductSubVersion + " available. Please update.");
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.error("failure");
714
+ callbackContext.success("success");
715
+ } catch (Exception e) {
716
+ callbackContext.error(e.getMessage());
603
717
  }
604
- });
605
- builder.setNegativeButton("Not Now", new DialogInterface.OnClickListener() {
606
- @Override
607
- public void onClick(DialogInterface dialog, int which) {
608
- dialog.cancel();
609
- callbackContext.success("Success");
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
- alertDialog = builder.create();
613
- alertDialog.setCanceledOnTouchOutside(false);
614
- alertDialog.show();
615
- alertDialog.setOnKeyListener(new DialogInterface.OnKeyListener() {
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
- } else if (action.equals("UpdateConfirm")) {
628
- /* OPEN THE PLAYSTORE MSERVICE APP */
629
- String appVersion, softwareProductVersion, softwareProductSubVersion;
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
- } else if (action.equals("UpdateNew")) {
661
- cordova.getActivity().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("https://play.google.com/store/apps/details?id=" + cordova.getActivity().getApplicationContext().getPackageName())));
662
- callbackContext.error("failure");
663
- } else if (action.equals("OpenFileWithViewer")) {
664
- Context context = cordova.getActivity().getApplicationContext();
665
- String filePath = "";
666
- if (args.optString(0).contains("Android/data/com.selfservit.doubleo/files/")) {
667
- filePath = mInterfaceUtil.rootDirectory + "/" + (args.optString(0).replace("Android/data/com.selfservit.doubleo/files/",""));
668
- } else {
669
- filePath = mInterfaceUtil.rootDirectory + "/" + args.optString(0);
670
- }
671
- File imageFilePath = new File(filePath);
672
- try {
673
- Intent intent = new Intent(Intent.ACTION_VIEW);
674
- Uri contentUri = FileProvider.getUriForFile(context, context.getPackageName() + ".provider", imageFilePath);
675
- intent.setDataAndType(contentUri, getMimeType(filePath, null));
676
- intent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION | Intent.FLAG_ACTIVITY_NO_HISTORY);
677
- cordova.getActivity().startActivity(intent);
678
- callbackContext.success();
679
- } catch (ActivityNotFoundException e) {
680
- callbackContext.error(1);
681
- }
682
- } else if (action.equals("CaptureImageFromCamera")) {
683
- try {
684
- if (args.length() > 0) {
685
- attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
686
- cameraAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
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
- } catch (Exception e) {
691
- callbackContext.error("ms058");
692
- }
693
- } else if (action.equals("PickImageFromGallery")) {
694
- try {
695
- if (args.length() > 0) {
696
- attachmentDestPath = args.optJSONObject(0).optString("destinationPath");
697
- galleryAttachmentInd = args.getJSONObject(0).optString("attachmentInd");
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());
799
+ }
800
+ } else if (action.equals("ScanBarCode")) {
801
+ try {
802
+ scanBarCode(callbackContext);
803
+ return true;
804
+ } catch (Exception e) {
805
+ callbackContext.error(e.getMessage());
698
806
  }
699
- pickImageFromGallery(callbackContext);
807
+ } else if (action.equals("GetSubDirectoryList")) {
808
+ new mInterfaceUtil().getSubDirectoryList(args, callbackContext);
700
809
  return true;
701
- } catch (Exception e) {
702
- callbackContext.error("ms059");
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
- } catch (Exception e) {
709
- callbackContext.error(1);
710
- }
711
- } else if (action.equals("DeleteSrcFile")) {
712
- try {
713
- String filePath = args.getJSONObject(0).optString("filePath");
714
- String fileName = args.getJSONObject(0).optString("fileName");
715
- File fullPath = new File(filePath + "/" + fileName);
716
- if (fullPath.exists()) {
717
- fullPath.delete();
718
- callbackContext.success();
719
- } else {
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
- } catch (Exception e) {
738
- callbackContext.error("ms060");
739
- }
740
- } else if (action.equals("ScanBarCode")) {
741
- try {
742
- scanBarCode(callbackContext);
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
- } catch (Exception e) {
745
- callbackContext.error("ms061");
746
- }
747
- } else if (action.equals("GetSubDirectoryList")) {
748
- new mInterfaceUtil().getSubDirectoryList(args, callbackContext);
749
- return true;
750
- } else if (action.equals("GetFileList")) {
751
- new mInterfaceUtil().getFileList(args, callbackContext);
752
- return true;
753
- } else if (action.equals("GetAppStateInfo")) {
754
- boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
755
- if (appInfoUpdated) {
756
- System.out.println("app info updated");
757
- new mInterfaceUtil().getAppStateInfo(callbackContext, cordova.getActivity().getApplicationContext());
758
- } else {
759
- System.out.println("app info not updated");
760
- callbackContext.success("");
761
- }
762
- return true;
763
- } else if (action.equals("UpdateAppInfo")) {
764
- boolean appInfoUpdated = new mInterfaceUtil().updateAppInfo(args);
765
- if (appInfoUpdated) {
766
- callbackContext.success("success");
767
- } else {
768
- callbackContext.error("failed to update app info");
769
- }
770
- return true;
771
- } else if (action.equals("MoveFile")) {
772
- arguments = args;
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, "MOBILE_INVALID");
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
- } else {
805
- result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
876
+ } catch (JSONException e) {
877
+ e.printStackTrace();
878
+ result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
806
879
  callback.sendPluginResult(result);
807
880
  }
808
- } catch (JSONException e) {
809
- e.printStackTrace();
810
- result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
811
- callback.sendPluginResult(result);
812
- }
813
- return true;
814
- } else if (action.equals("OpenDialPad")) {
815
- Intent intent;
816
- PluginResult result;
817
- try {
818
- String contact_number = args.getJSONObject(0).optString("contact_number");
819
- if (contact_number != null) {
820
- if (!contact_number.equals("")) {
821
- if (validateMobileNumber(contact_number)) {
822
-
823
- intent = new Intent(Intent.ACTION_DIAL);
824
- intent.setData(Uri.parse("tel:" + contact_number));
825
- intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
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, "MOBILE_INVALID");
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
- } else {
836
- result = new PluginResult(PluginResult.Status.ERROR, "MOBILE_NOT_AVAILABLE");
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
- return true;
841
- } catch (Exception exception) {
842
- System.out.println(exception.getMessage());
843
- result = new PluginResult(PluginResult.Status.ERROR, exception.getMessage());
844
- callback.sendPluginResult(result);
845
- }
846
- } else if (action.equals("OpenEmail")) {
847
- PluginResult result;
848
- String toEmail, ccEmail, subject, body, mailto;
849
- try {
850
- toEmail = args.getJSONObject(0).optString("toEmail");
851
- ccEmail = args.getJSONObject(0).optString("ccEmail");
852
- subject = args.getJSONObject(0).optString("subject");
853
- body = args.getJSONObject(0).optString("body");
854
- if (toEmail != null) {
855
- if (!toEmail.equals("")) {
856
- if (Patterns.EMAIL_ADDRESS.matcher(toEmail).matches()) {
857
- mailto = "mailto:" + toEmail +
858
- "?cc=" + ccEmail +
859
- "&subject=" + Uri.encode(subject) +
860
- "&body=" + Uri.encode(body);
861
- Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
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, "EMAIL_INVALID");
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
- } else {
874
- result = new PluginResult(PluginResult.Status.ERROR, "EMAIL_NOT_AVAILABLE");
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
- } else if (action.equals("OpenAppSettings")) {
884
- PluginResult result;
885
- try {
886
- Intent intent = new Intent(Settings.ACTION_APPLICATION_DETAILS_SETTINGS);
887
- Uri uri = Uri.fromParts("package", cordova.getActivity().getPackageName(), null);
888
- intent.setData(uri);
889
- cordova.getActivity().startActivity(intent);
890
- callbackContext.success("success");
891
- } catch (Exception e) {
892
- e.printStackTrace();
893
- result = new PluginResult(PluginResult.Status.ERROR, e.getMessage());
894
- callback.sendPluginResult(result);
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
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
917
- return Settings.Global.getInt(c.getContentResolver(), Settings.Global.AUTO_TIME, 0) == 1;
918
- } else {
919
- return android.provider.Settings.System.getInt(c.getContentResolver(), android.provider.Settings.System.AUTO_TIME, 0) == 1;
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
- mLocationRequest1 = new LocationRequest();
925
- mLocationRequest1.setInterval(INTERVAL);
926
- mLocationRequest1.setFastestInterval(FASTEST_INTERVAL);
927
- mLocationRequest1.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
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
- callback = callbackContext;
953
- SCANCODEINT = 118;
954
- IntentIntegrator integrator = new IntentIntegrator(this.cordova.getActivity());
955
- integrator.setDesiredBarcodeFormats(IntentIntegrator.QR_CODE);
956
- integrator.setPrompt("Scan");
957
- integrator.setCameraId(0);
958
- integrator.setBeepEnabled(true);
959
- integrator.setBarcodeImageEnabled(true);
960
- integrator.initiateScan();
961
- cordova.setActivityResultCallback(this);
962
- PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
963
- pluginResult.setKeepCallback(true);
964
- callbackContext.sendPluginResult(pluginResult);
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
- callback = callbackContext;
969
- SCANCODEINT = 119;
970
- IntentIntegrator integrator = new IntentIntegrator(this.cordova.getActivity());
971
- integrator.setDesiredBarcodeFormats(IntentIntegrator.ONE_D_CODE_TYPES);
972
- integrator.setPrompt("Scan");
973
- integrator.setCameraId(0);
974
- integrator.setBeepEnabled(true);
975
- integrator.setBarcodeImageEnabled(true);
976
- integrator.initiateScan();
977
- cordova.setActivityResultCallback(this);
978
- PluginResult pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
979
- pluginResult.setKeepCallback(true);
980
- callbackContext.sendPluginResult(pluginResult);
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
- callbackContext.success("file://" + mInterfaceUtil.rootDirectory + "/");
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.printStackTrace();
1171
+ callback.error(e.getMessage());
1080
1172
  }
1081
1173
  }
1082
1174
 
@@ -1133,24 +1225,27 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1133
1225
  }
1134
1226
 
1135
1227
  public void pickImageFromGallery(CallbackContext callbackContext) {
1136
- Intent openFile,
1137
- selectFile;
1138
- PluginResult pluginResult;
1139
- callback = callbackContext;
1140
- if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
1141
- // Use the ACTION_OPEN_DOCUMENT intent for Android 13 and higher
1142
- openFile = new Intent(MediaStore.ACTION_PICK_IMAGES);
1143
- openFile.setType("image/*");
1144
- } else {
1145
- openFile = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
1146
- openFile.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
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/*");
1237
+ } else {
1238
+ openFile = new Intent(Intent.ACTION_PICK, MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
1239
+ openFile.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
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());
1147
1248
  }
1148
-
1149
- selectFile = Intent.createChooser(openFile, "Select File");
1150
- cordova.startActivityForResult(this,selectFile, PICK_IMAGE_FROM_GALLERY);
1151
- pluginResult = new PluginResult(PluginResult.Status.NO_RESULT);
1152
- pluginResult.setKeepCallback(true);
1153
- callbackContext.sendPluginResult(pluginResult);
1154
1249
  }
1155
1250
 
1156
1251
  private String getMimeType(String path, Uri uri) {
@@ -1176,33 +1271,43 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1176
1271
  }
1177
1272
 
1178
1273
  private File createImageFile() throws IOException {
1179
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1180
- String imageFileName = "JPEG_" + timeStamp + "_";
1181
- String filePath = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/images";
1182
- File storageDir = new File(filePath);
1183
- if (!storageDir.exists()) {
1184
- storageDir.mkdirs();
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();
1185
1287
  }
1186
- File image = File.createTempFile(imageFileName, /* prefix */".jpg", /* suffix */storageDir /* directory */);
1187
- pictureFilePath = image.getAbsolutePath();
1188
- return image;
1288
+ return null;
1189
1289
  }
1190
1290
 
1191
1291
  public int calculateInSampleSize(BitmapFactory.Options options, int reqWidth, int reqHeight) {
1192
- final int height = options.outHeight;
1193
- final int width = options.outWidth;
1194
- int inSampleSize = 1;
1195
- if (height > reqHeight || width > reqWidth) {
1196
- final int heightRatio = Math.round((float) height / (float) reqHeight);
1197
- final int widthRatio = Math.round((float) width / (float) reqWidth);
1198
- inSampleSize = heightRatio < widthRatio ? heightRatio : widthRatio;
1199
- }
1200
- final float totalPixels = width * height;
1201
- final float totalReqPixelsCap = reqWidth * reqHeight * 2;
1202
- while (totalPixels / (inSampleSize * inSampleSize) > totalReqPixelsCap) {
1203
- 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();
1204
1309
  }
1205
- return inSampleSize;
1310
+ return 0;
1206
1311
  }
1207
1312
 
1208
1313
  public void convertImageTo64BaseString(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
@@ -1215,17 +1320,18 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1215
1320
  Bitmap bitmap;
1216
1321
  BitmapFactory.Options options = new BitmapFactory.Options();
1217
1322
  options.inJustDecodeBounds = true;
1218
- String[] bits = imageSourcePath.split("/");
1323
+ try {
1324
+ String[] bits = imageSourcePath.split("/");
1219
1325
 
1220
- String fileNameToSend = bits[bits.length - 1];
1221
- if (fileNameToSend.indexOf(".") > 0)
1222
- fileNameToSend = fileNameToSend.substring(0, fileNameToSend.lastIndexOf("."));
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;
1223
1333
 
1224
- File fileToCompress = new File(imageSourcePath);
1225
- String thumbnail = getFileThumbnail(imageSourcePath, "." + imageSourcePath.substring(imageSourcePath.lastIndexOf(".") + 1).toLowerCase());
1226
- File compressedImageFile;
1227
1334
 
1228
- try {
1229
1335
  compressedImageFile = new Compressor(cordova.getActivity())
1230
1336
  .setQuality(15)
1231
1337
  .setCompressFormat(Bitmap.CompressFormat.JPEG)
@@ -1312,7 +1418,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1312
1418
  callbackContext.error(e.getMessage());
1313
1419
  }
1314
1420
 
1315
- } catch (IOException e) {
1421
+ } catch (Exception e) {
1316
1422
  e.printStackTrace();
1317
1423
  }
1318
1424
 
@@ -1481,11 +1587,12 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1481
1587
 
1482
1588
  public String getBase64String(String imageSourcePath) {
1483
1589
  String resultString = "";
1484
- String filePath = mInterfaceUtil.rootDirectory + "/" + imageSourcePath;
1485
- File image = new File(filePath);
1486
- BitmapFactory.Options bmOptions = new BitmapFactory.Options();
1487
- Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
1488
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
+
1489
1596
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1490
1597
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
1491
1598
  resultString = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
@@ -1510,17 +1617,22 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1510
1617
 
1511
1618
  public Intent getPickImageChooserIntent() {
1512
1619
  Intent openFile, selectFile;
1513
- if (Build.MANUFACTURER.equals("samsung")) {
1514
- openFile = new Intent("com.sec.android.app.myfiles.PICK_DATA");
1515
- openFile.putExtra("CONTENT_TYPE", "*/*");
1516
- } else {
1517
- openFile = new Intent(Intent.ACTION_GET_CONTENT);
1518
- openFile.setType("*/*");
1519
- openFile.addCategory(Intent.CATEGORY_OPENABLE);
1520
- openFile.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
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();
1521
1634
  }
1522
- selectFile = Intent.createChooser(openFile, "Select File");
1523
- return selectFile;
1635
+ return null;
1524
1636
  }
1525
1637
 
1526
1638
  //App version plugin
@@ -1528,299 +1640,319 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1528
1640
  try {
1529
1641
  PackageManager packageManager = this.cordova.getActivity().getPackageManager();
1530
1642
  JSONObject r = new JSONObject();
1531
- try {
1532
- r.put("version", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionName);
1533
- r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
1534
- } catch (JSONException e) {
1535
- e.printStackTrace();
1536
- }
1643
+ r.put("version", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionName);
1644
+ r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
1537
1645
  callbackContext.success(r);
1538
- } catch (PackageManager.NameNotFoundException e) {
1539
- callbackContext.error("Exception thrown");
1646
+ } catch (Exception e) {
1647
+ callbackContext.error(e.getMessage());
1540
1648
  }
1541
1649
  }
1542
1650
 
1543
1651
  //Rotate Screen plugin
1544
1652
  public void rotateScreen(JSONArray args, CallbackContext callbackContext) {
1545
- String orientation = args.optString(0);
1546
- String currentOrientation;
1547
- Activity activity = cordova.getActivity();
1548
- int orientation1 = activity.getResources().getConfiguration().orientation;
1549
- if (orientation1 == Configuration.ORIENTATION_LANDSCAPE) {
1550
- currentOrientation = "landscape";
1551
- } else {
1552
- currentOrientation = "portrait";
1553
- }
1554
- if (orientation.equals(ANY)) {
1555
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1556
- } else if (orientation.equals(LANDSCAPE_PRIMARY)) {
1557
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
1558
- } else if (orientation.equals(PORTRAIT_PRIMARY)) {
1559
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
1560
- } else if (orientation.equals(LANDSCAPE)) {
1561
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
1562
- } else if (orientation.equals(PORTRAIT)) {
1563
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
1564
- } else if (orientation.equals(LANDSCAPE_SECONDARY)) {
1565
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
1566
- } else if (orientation.equals(PORTRAIT_SECONDARY)) {
1567
- activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
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());
1568
1681
  }
1569
- callbackContext.success(currentOrientation);
1570
1682
  }
1571
1683
 
1572
- public void deviceInfo(CallbackContext callbackContext) throws JSONException {
1573
- String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), Settings.Secure.ANDROID_ID);
1574
- JSONObject r = new JSONObject();
1575
- boolean a = android.os.Build.FINGERPRINT.contains("generic") ||
1576
- android.os.Build.PRODUCT.contains("sdk");
1577
- @SuppressWarnings("deprecation")
1578
- String sdkversion = android.os.Build.VERSION.SDK;
1579
- r.put("uuid", uuid);
1580
- r.put("version", android.os.Build.VERSION.RELEASE);
1581
- r.put("platform", ANDROID_PLATFORM);
1582
- r.put("model", android.os.Build.MODEL);
1583
- r.put("manufacturer", android.os.Build.MANUFACTURER);
1584
- r.put("isVirtual", a);
1585
- r.put("serial", android.os.Build.SERIAL);
1586
- r.put("timeZone", TimeZone.getDefault());
1587
- r.put("sdkVersion", sdkversion);
1588
- r.put("productName", android.os.Build.PRODUCT);
1589
- r.put("applicationName", getApplicationName(cordova.getActivity()));
1590
- callbackContext.success(r);
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
+ }
1591
1707
  }
1592
1708
 
1593
1709
  public static String getApplicationName(Context context) {
1594
- ApplicationInfo applicationInfo = context.getApplicationInfo();
1595
- int stringId = applicationInfo.labelRes;
1596
- return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
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 "";
1597
1718
  }
1598
1719
 
1599
1720
  @Override
1600
1721
  public void onActivityResult(int requestCode, int resultCode, Intent data) {
1601
- switch (requestCode) {
1602
- case LOCATION_ACCURACY_REQUEST_NEW:
1603
- switch (resultCode) {
1604
- case Activity.RESULT_OK:
1605
- mInterfaceService mInterfaceService = new mInterfaceService();
1606
- mInterfaceService.startLocationUpdates(cordova.getContext());
1607
- callback.success();
1608
- break;
1609
- case Activity.RESULT_CANCELED:
1610
- callback.error("oops! you have cancelled...");
1611
- break;
1612
- }
1613
- break;
1614
- }
1615
- if (SCANCODEINT == 118 && callback != null) {
1616
- if (resultCode == RESULT_OK) {
1617
- SCANCODEINT = 0;
1618
- IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
1619
- callback.success(result.getContents());
1620
- } else if (resultCode == Activity.RESULT_CANCELED) {
1621
- SCANCODEINT = 0;
1622
- callback.error("canceled");
1623
- } else {
1624
- SCANCODEINT = 0;
1625
- callback.error(resultCode);
1626
- }
1627
- } else if (SCANCODEINT == 119 && callback != null) {
1628
- if (resultCode == RESULT_OK) {
1629
- SCANCODEINT = 0;
1630
- IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
1631
- callback.success(result.getContents());
1632
- } else if (resultCode == Activity.RESULT_CANCELED) {
1633
- SCANCODEINT = 0;
1634
- callback.error("canceled");
1635
- } else {
1636
- SCANCODEINT = 0;
1637
- 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;
1638
1736
  }
1639
- } else if (requestCode == PICK_IMAGE_FROM_GALLERY && callback != null) {
1640
- if (resultCode == RESULT_OK) {
1641
- String fileName = null, getfilePath = null, filePath, fileType, storageDefinition, fileExtension;
1642
- final String docId, type, id;
1643
- final String[] split;
1644
- final String tag, path;
1645
- final int splitIndex;
1646
- Cursor cursor;
1647
- Uri uri = data.getData(); //get uri for selected file
1648
- fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
1649
- File getFileName, file;
1650
- try {
1651
- //API LEVEL 19 AND ABOVE (TO GET FILEPATH)
1652
- if (Build.VERSION.SDK_INT >= 19 && !Build.MANUFACTURER.equals("samsung") && DocumentsContract.isDocumentUri(cordova.getActivity(), uri)) {
1653
- if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { // ExternalStorageProvider
1654
- docId = DocumentsContract.getDocumentId(uri);
1655
- split = docId.split(":");
1656
- type = split[0];
1657
- if ("primary".equalsIgnoreCase(type)) {
1658
- getfilePath = mInterfaceUtil.rootDirectory + "/" + split[1];
1659
- } else {
1660
- if (Environment.isExternalStorageRemovable()) {
1661
- storageDefinition = System.getenv("EXTERNAL_STORAGE");
1662
- getfilePath = storageDefinition;
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];
1663
1781
  } else {
1664
- splitIndex = docId.indexOf(':', 1);
1665
- tag = docId.substring(0, splitIndex);
1666
- path = docId.substring(splitIndex + 1);
1667
- if (new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) != null) {
1668
- storageDefinition = new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) + "/" + path;
1669
- file = new File(storageDefinition);
1670
- if (file.exists() && file.canRead()) {
1671
- getfilePath = storageDefinition;
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
+ }
1672
1795
  }
1673
1796
  }
1674
1797
  }
1675
- }
1676
- } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { // DownloadsProvider
1677
- id = DocumentsContract.getDocumentId(uri);
1678
- final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
1679
- getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, null, null);
1680
- } else if ("com.android.providers.media.documents".equals(uri.getAuthority())) { // MediaProvider
1681
- docId = DocumentsContract.getDocumentId(uri);
1682
- split = docId.split(":");
1683
- type = split[0];
1684
- Uri contentUri = null;
1685
- if ("image".equals(type)) {
1686
- contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
1687
- } else if ("video".equals(type)) {
1688
- contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
1689
- } else if ("audio".equals(type)) {
1690
- contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
1691
- }
1692
- final String selection = "_id=?";
1693
- final String[] selectionArgs = new String[]{
1694
- split[1]
1695
- };
1696
- getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
1697
- }
1698
- // *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
1699
- cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
1700
- try {
1701
- if (cursor != null && cursor.moveToFirst()) {
1702
- int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
1703
- if (displayNameIndex != -1) {
1704
- fileName = cursor.getString(displayNameIndex);
1705
- } else {
1706
- 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;
1707
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);
1708
1819
  }
1709
- } finally {
1710
- cursor.close();
1711
- }
1712
- // *** API Level 19 below and SAMSUNG (To Get FileProperties of MediaFiles)**** //
1713
- } else {
1714
- if (fileType != null) {
1715
- String[] projection = {
1716
- MediaStore.Images.Media.DATA,
1717
- MediaStore.Images.Media.SIZE,
1718
- MediaStore.Images.Media.DISPLAY_NAME
1719
- };
1720
- cursor = cordova.getActivity().getContentResolver().query(uri, projection, null, null, null);
1721
- if (cursor.moveToFirst()) {
1722
- getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
1723
- 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();
1724
1833
  }
1725
- cursor.close();
1726
- // 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)**** //
1727
1835
  } else {
1728
- getfilePath = data.getData().getPath();
1729
- filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
1730
- getFileName = new File(getfilePath);
1731
- fileName = getFileName.getName();
1732
- }
1733
- }
1734
- filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
1735
- fileExtension = "." + getfilePath.substring(getfilePath.lastIndexOf(".") + 1).toLowerCase();
1736
- if (filePath != null) {
1737
- try {
1738
- if (fileExtension.equals(".heic")) {
1739
- if (galleryAttachmentInd.equals("true")) {
1740
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1741
- } else {
1742
- 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));
1743
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
+ }
1744
1866
 
1745
- } else if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
1746
- if (galleryAttachmentInd.equals("true")) {
1747
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
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
+ }
1748
1873
  } else {
1749
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
1874
+ callback.error("Only JPEG or PNG file extensions are allowed to attach.");
1750
1875
  }
1751
- } else {
1876
+ } catch (Exception e) {
1752
1877
  callback.error("Only JPEG or PNG file extensions are allowed to attach.");
1753
1878
  }
1754
- } catch (Exception e) {
1755
- callback.error("Only JPEG or PNG file extensions are allowed to attach.");
1879
+ } else {
1880
+ callback.error("File path was null");
1756
1881
  }
1757
- } else {
1758
- callback.error("File path was null");
1759
- }
1760
- } catch (Exception e) {
1761
- e.printStackTrace();
1762
- }
1763
- } else if (resultCode == Activity.RESULT_CANCELED) {
1764
- callback.error("failure");
1765
- } else {
1766
- callback.error(resultCode);
1767
- }
1768
- } else if (requestCode == NEW_FILE_PICK_REQUEST && callback != null) {
1769
- try {
1770
- Uri uri = data.getData();
1771
- String fileName, extension, filePath;
1772
- JSONObject fileProperities;
1773
- Cursor cursor = null;
1774
- if (uri.getScheme().equals("file")) {
1775
- fileName = uri.getLastPathSegment();
1776
- if (fileName.indexOf(".") > 0) {
1777
- fileName = fileName.substring(0, fileName.lastIndexOf("."));
1778
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1779
- extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1780
- fileName = fileName + "_" + timeStamp + extension;
1882
+ } catch (Exception e) {
1883
+ e.printStackTrace();
1781
1884
  }
1885
+ } else if (resultCode == Activity.RESULT_CANCELED) {
1886
+ callback.error("failure");
1782
1887
  } else {
1783
- try {
1784
- cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DISPLAY_NAME}, null, null, null);
1785
- if (cursor != null && cursor.moveToFirst()) {
1786
- int displayNameIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME);
1787
- if (displayNameIndex != -1) {
1788
- fileName = cursor.getString(displayNameIndex);
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
+
1789
1921
  } else {
1790
- fileName = "";
1922
+ fileName = uri.getLastPathSegment();
1791
1923
  }
1792
- extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1793
- if (!extension.equals(".jpeg") && !extension.equals(".jpg") && !extension.equals(".png")) {
1794
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1795
- fileName = fileName.substring(0, fileName.lastIndexOf("."));
1796
- fileName = fileName + "_" + timeStamp + extension;
1924
+ } finally {
1925
+ if (cursor != null) {
1926
+ cursor.close();
1797
1927
  }
1798
-
1799
- } else {
1800
- fileName = uri.getLastPathSegment();
1801
- }
1802
- } finally {
1803
- if (cursor != null) {
1804
- cursor.close();
1805
1928
  }
1806
1929
  }
1807
- }
1808
1930
 
1809
- extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1931
+ extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1810
1932
 
1811
- filePath = copyFileFromUri(cordova.getActivity().getApplicationContext(), uri, fileName, attachmentDestPath, callback);
1812
- File file = new File(filePath);
1813
- String mimeType = getMimeType(filePath, uri);
1814
- System.out.println("Mime type is: " + mimeType);
1815
- double fileSize = file.length();
1816
- if (filePath != null) {
1817
- try {
1818
- if (requestCode == NEW_FILE_PICK_REQUEST) {
1819
- if (extension.equals(".heic")) {
1820
- convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
1821
- } else if (mimeType != null) {
1822
- 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")) {
1823
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
+ }
1824
1956
  } else {
1825
1957
  fileProperities = new JSONObject();
1826
1958
  fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
@@ -1828,207 +1960,200 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1828
1960
  fileProperities.put("fileSize", fileSize);
1829
1961
  fileProperities.put("fileExtension", extension);
1830
1962
  fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
1831
- attachmentDestPath = "";
1832
1963
  callback.success(fileProperities);
1833
1964
  }
1834
- } else {
1835
- fileProperities = new JSONObject();
1836
- fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
1837
- fileProperities.put("fileName", fileName);
1838
- fileProperities.put("fileSize", fileSize);
1839
- fileProperities.put("fileExtension", extension);
1840
- fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
1841
- callback.success(fileProperities);
1842
1965
  }
1966
+ } catch (Exception e) {
1967
+ callback.error(e.getMessage());
1843
1968
  }
1844
- } catch (Exception e) {
1845
- callback.error(e.getMessage());
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();
1846
1987
  }
1988
+ callback.error("failure");
1847
1989
  } else {
1848
- callback.error("Selected file path is null");
1990
+ callback.error(resultCode);
1849
1991
  }
1850
- } catch (Exception e) {
1851
- callback.error(e.getMessage());
1852
- }
1853
- } else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
1854
- if (resultCode == RESULT_OK) {
1855
- if (cameraAttachmentInd.equals("true")) {
1992
+ } else if (requestCode == REQUEST_LIVE_IMAGE_CAPTURE && callback != null) {
1993
+ if (resultCode == RESULT_OK) {
1856
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");
1857
2001
  } else {
1858
- convertImageTo64BaseString(callback, pictureFilePath, "camera", "");
2002
+ callback.error(resultCode);
1859
2003
  }
1860
-
1861
- } else if (resultCode == Activity.RESULT_CANCELED) {
1862
- File file = new File(pictureFilePath);
1863
- if (file.exists()) {
1864
- file.delete();
1865
- }
1866
- callback.error("failure");
1867
- } else {
1868
- callback.error(resultCode);
1869
- }
1870
- } else if (requestCode == REQUEST_LIVE_IMAGE_CAPTURE && callback != null) {
1871
- if (resultCode == RESULT_OK) {
1872
- convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
1873
- } else if (resultCode == Activity.RESULT_CANCELED) {
1874
- File file = new File(pictureFilePath);
1875
- if (file.exists()) {
1876
- file.delete();
1877
- }
1878
- callback.error("failure");
1879
- } else {
1880
- callback.error(resultCode);
1881
- }
1882
- } else if (requestCode == PICK_FILE_REQUEST && callback != null) {
1883
- if (resultCode == RESULT_OK) {
1884
- String fileName = null,
1885
- getfilePath = null,
1886
- filePath,
1887
- fileExtension,
1888
- fileType,
1889
- fileSize = null,
1890
- storageDefinition;
1891
- final String docId,
1892
- type,
1893
- id;
1894
- final String[] split;
1895
- final String tag,
1896
- path;
1897
- final int splitIndex;
1898
- Cursor cursor;
1899
- long getSize;
1900
- JSONObject fileProperities;
1901
- Uri uri = data.getData(); //get uri for selected file
1902
- fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
1903
- File getFileName,
1904
- file;
1905
- try {
1906
- //API LEVEL 19 AND ABOVE (TO GET FILEPATH)
1907
- if (Build.VERSION.SDK_INT >= 19 && !Build.MANUFACTURER.equals("samsung") && DocumentsContract.isDocumentUri(cordova.getActivity(), uri)) {
1908
- if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { // ExternalStorageProvider
1909
- docId = DocumentsContract.getDocumentId(uri);
1910
- split = docId.split(":");
1911
- type = split[0];
1912
- if ("primary".equalsIgnoreCase(type)) {
1913
- getfilePath = mInterfaceUtil.rootDirectory + "/" + split[1];
1914
- } else {
1915
- if (Environment.isExternalStorageRemovable()) {
1916
- storageDefinition = System.getenv("EXTERNAL_STORAGE");
1917
- 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];
1918
2036
  } else {
1919
- splitIndex = docId.indexOf(':', 1);
1920
- tag = docId.substring(0, splitIndex);
1921
- path = docId.substring(splitIndex + 1);
1922
- if (new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) != null) {
1923
- storageDefinition = new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) + "/" + path;
1924
- file = new File(storageDefinition);
1925
- if (file.exists() && file.canRead()) {
1926
- getfilePath = storageDefinition;
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
+ }
1927
2050
  }
1928
2051
  }
1929
2052
  }
1930
- }
1931
- } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { // DownloadsProvider
1932
- id = DocumentsContract.getDocumentId(uri);
1933
- final Uri contentUri = ContentUris.withAppendedId(
1934
- Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
1935
- getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, null, null);
1936
-
1937
- } else if ("com.android.providers.media.documents".equals(uri.getAuthority())) { // MediaProvider
1938
- docId = DocumentsContract.getDocumentId(uri);
1939
- split = docId.split(":");
1940
- type = split[0];
1941
- Uri contentUri = null;
1942
- if ("image".equals(type)) {
1943
- contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
1944
- } else if ("video".equals(type)) {
1945
- contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
1946
- } else if ("audio".equals(type)) {
1947
- contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
1948
- }
1949
- final String selection = "_id=?";
1950
- final String[] selectionArgs = new String[]{
1951
- split[1]
1952
- };
1953
- getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
1954
- }
1955
- // *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
1956
- cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
1957
- try {
1958
- if (cursor != null && cursor.moveToFirst()) {
1959
- int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
1960
- if (displayNameIndex != -1) {
1961
- fileName = cursor.getString(displayNameIndex);
1962
- } else {
1963
- 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;
1964
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
+ }
1965
2087
 
1966
- int fileSizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
1967
- if (!cursor.isNull(fileSizeIndex) && fileSizeIndex != -1) {
1968
- fileSize = cursor.getString(fileSizeIndex);
1969
- } else {
1970
- fileSize = "0";
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
+ }
1971
2094
  }
2095
+ } finally {
2096
+ cursor.close();
1972
2097
  }
1973
- } finally {
1974
- cursor.close();
1975
- }
1976
- // *** API Level 19 below and SAMSUNG (To Get FileProperties of MediaFiles)**** //
1977
- } else {
1978
- if (fileType != null) {
1979
- String[] projection = {
1980
- MediaStore.Images.Media.DATA,
1981
- MediaStore.Images.Media.SIZE,
1982
- MediaStore.Images.Media.DISPLAY_NAME
1983
- };
1984
- cursor = cordova.getActivity().getContentResolver().query(uri, projection, null, null, null);
1985
- if (cursor.moveToFirst()) {
1986
- getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
1987
- fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
1988
- fileSize = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE));
1989
- }
1990
- cursor.close();
1991
- // 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)**** //
1992
2099
  } else {
1993
- getfilePath = data.getData().getPath();
1994
- filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
1995
- getFileName = new File(getfilePath);
1996
- fileName = getFileName.getName();
1997
- getSize = getFileName.length();
1998
- fileSize = String.valueOf(getSize);
1999
- }
2000
- }
2001
- filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
2002
- fileExtension = "." + getfilePath.substring(getfilePath.lastIndexOf(".") + 1).toLowerCase();
2003
- // SEND BELOW JSON OBJECT TO PLUGIN CALLBACK
2004
- if (filePath != null) {
2005
- try {
2006
- if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
2007
- 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..,))
2008
2114
  } else {
2009
- fileProperities = new JSONObject();
2010
- fileProperities.put("filePath", filePath);
2011
- fileProperities.put("fileName", fileName);
2012
- fileProperities.put("fileSize", fileSize);
2013
- fileProperities.put("fileExtension", fileExtension);
2014
- callback.success(fileProperities);
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);
2015
2121
  }
2016
- } catch (Exception e) {
2017
- callback.error("Failed to process PICK_FILE_REQUEST");
2018
2122
  }
2019
- } else {
2020
- callback.error("File path was null");
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();
2021
2146
  }
2022
- } catch (Exception e) {
2023
- e.printStackTrace();
2147
+ } else if (resultCode == Activity.RESULT_CANCELED) {
2148
+ callback.error("failure");
2149
+ } else {
2150
+ callback.error(resultCode);
2024
2151
  }
2025
- } else if (resultCode == Activity.RESULT_CANCELED) {
2026
- callback.error("failure");
2027
2152
  } else {
2028
- callback.error(resultCode);
2153
+ callback.error("failure");
2029
2154
  }
2030
- } else {
2031
- callback.error("failure");
2155
+ } catch (Exception e) {
2156
+ e.printStackTrace();
2032
2157
  }
2033
2158
  }
2034
2159
 
@@ -2094,48 +2219,65 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2094
2219
 
2095
2220
  /* CHECKING THE BACKGROUND SERVICE RUNNING OR NOT */
2096
2221
  private boolean isServiceRunning(Class<?> serviceClass) {
2097
- ActivityManager manager = (ActivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
2098
- for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
2099
- if (serviceClass.getName().equals(service.service.getClassName())) {
2100
- return true;
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
+ }
2101
2228
  }
2229
+
2230
+ } catch (SecurityException e) {
2231
+ e.printStackTrace();
2102
2232
  }
2103
2233
  return false;
2104
2234
  }
2105
2235
 
2106
2236
  private boolean isProcessRunning() {
2107
- ActivityManager manager1 = (ActivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
2108
- for (ActivityManager.RunningAppProcessInfo processInfo : manager1.getRunningAppProcesses()) {
2109
- if (processInfo.processName.equals(cordova.getActivity().getPackageName())) {
2110
- return true;
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
+ }
2111
2243
  }
2244
+ } catch (Exception e) {
2245
+ e.printStackTrace();
2112
2246
  }
2113
2247
  return false;
2114
2248
  }
2115
2249
 
2116
2250
  private void EnableGPSAutomatically(CallbackContext callbackContext) {
2117
- callback = callbackContext;
2118
- createLocationRequest1();
2119
- mGoogleApiClient1 = new GoogleApiClient.Builder(cordova.getActivity())
2120
- .addApi(LocationServices.API).addConnectionCallbacks(this)
2121
- .addOnConnectionFailedListener(this).build();
2122
- mGoogleApiClient1.connect();
2123
- LocationRequest locationRequest = LocationRequest.create();
2124
- locationRequest.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
2125
- locationRequest.setInterval(30 * 1000);
2126
- locationRequest.setFastestInterval(5 * 1000);
2127
- LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
2128
- .addLocationRequest(locationRequest);
2129
- builder.setAlwaysShow(true); // this is the key ingredient
2130
- PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi
2131
- .checkLocationSettings(mGoogleApiClient1, builder.build());
2132
- result.setResultCallback(this);
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
+ }
2133
2271
  }
2134
2272
 
2135
2273
  @Override
2136
2274
  public void onConnected(@Nullable Bundle bundle) {
2137
- if (mGoogleApiClient1.isConnected()) {
2138
- startLocationUpdates1();
2275
+ try {
2276
+ if (mGoogleApiClient1.isConnected()) {
2277
+ startLocationUpdates1();
2278
+ }
2279
+ } catch (Exception e) {
2280
+ System.out.println(e.getMessage());
2139
2281
  }
2140
2282
  }
2141
2283
 
@@ -2149,21 +2291,25 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2149
2291
 
2150
2292
  @Override
2151
2293
  public void onResult(LocationSettingsResult locationSettingsResult) {
2152
- final Status status = locationSettingsResult.getStatus();
2153
- switch (status.getStatusCode()) {
2154
- case LocationSettingsStatusCodes.SUCCESS:
2155
- break;
2156
- case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
2157
- try {
2158
- this.cordova.setActivityResultCallback(this);
2159
- status.startResolutionForResult(this.cordova.getActivity(), LOCATION_ACCURACY_REQUEST_NEW);
2160
- } catch (IntentSender.SendIntentException e) {
2161
- System.out.println("PendingIntent unable to execute request: ");
2162
- }
2163
- break;
2164
- case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
2165
- System.out.println("Location settings are inadequate, and cannot be fixed here. Dialog not created.");
2166
- break;
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());
2167
2313
  }
2168
2314
  }
2169
2315
 
@@ -2252,29 +2398,38 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2252
2398
  String thumbnail = getFileThumbnail(filePath, extension);
2253
2399
  downloadFileCallback.success(thumbnail);
2254
2400
  } else {
2255
- downloadFileCallback.error("Failure...");
2401
+ downloadFileCallback.error("Failure");
2256
2402
  }
2257
2403
  } else {
2258
2404
  System.out.println("success");
2259
2405
  downloadFileCallback.success("");
2260
2406
  }
2261
2407
  } catch (Exception e) {
2262
- e.printStackTrace();
2408
+ downloadFileCallback.error(e.getMessage());
2263
2409
  }
2264
2410
  }
2265
2411
  }
2266
2412
 
2267
2413
  public static String pathComponent(String filename) {
2268
- int i = filename.lastIndexOf(File.separator);
2269
- return (i > -1) ? filename.substring(0, i) : filename;
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 "";
2270
2421
  }
2271
2422
 
2272
2423
  private void unzip(final JSONArray args, final CallbackContext callbackContext) {
2273
- this.cordova.getThreadPool().execute(new Runnable() {
2274
- public void run() {
2275
- unzipSync(args, callbackContext);
2276
- }
2277
- });
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
+ }
2278
2433
  }
2279
2434
 
2280
2435
  private void unzipSync(JSONArray args, CallbackContext callbackContext) {
@@ -2347,7 +2502,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2347
2502
  else
2348
2503
  callbackContext.error("Bad zip file");
2349
2504
  } catch (Exception e) {
2350
- String errorMessage = "An error occurred while unzipping.";
2505
+ String errorMessage = e.getMessage();
2351
2506
  callbackContext.error(errorMessage);
2352
2507
  } finally {
2353
2508
  if (inputStream != null) {
@@ -2377,9 +2532,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2377
2532
 
2378
2533
 
2379
2534
  public boolean isConnected() {
2380
- ConnectivityManager online = (ConnectivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
2381
- NetworkInfo networkInfo = online.getActiveNetworkInfo();
2382
- return networkInfo != null && networkInfo.isConnected();
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;
2383
2543
  }
2384
2544
 
2385
2545
 
@@ -2415,8 +2575,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2415
2575
  }
2416
2576
 
2417
2577
  public String convertBitmapToString(Bitmap bitmap) {
2418
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
2419
- bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
2420
- return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
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 "";
2421
2586
  }
2422
2587
  }