cordova-plugin-mserviceinterface-2.0 1.0.62 → 1.0.64

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;
@@ -125,7 +124,6 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
125
124
  private static final String PORTRAIT = "portrait";
126
125
  private static final String LANDSCAPE = "landscape";
127
126
  private static final String ANDROID_PLATFORM = "Android";
128
-
129
127
  String currentLocationInd = "";
130
128
  Location mCurrentLocation1;
131
129
  LocationRequest mLocationRequest1;
@@ -137,763 +135,836 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
137
135
  /* START SERVICE WHEN USER COMES FROM INACTIVE TO ACTIVE STATE IF SERVICE NOT RUNNING */
138
136
  @Override
139
137
  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));
138
+ try {
139
+ super.onResume(multitasking);
140
+ //To avoid starting service after getting permissions initially.
141
+ if (!mInterfaceUtil.deviceID.equalsIgnoreCase("")) {
142
+ if (!isServiceRunning(mInterfaceService.class) || !isProcessRunning()) {
143
+ cordova.getActivity().startService(new Intent(cordova.getActivity().getApplicationContext(), mInterfaceService.class));
144
+ }
145
145
  }
146
+ } catch (Exception e) {
147
+ System.out.println("onResume: " + e.getMessage());
146
148
  }
147
149
  }
148
150
 
149
151
  @RequiresApi(api = Build.VERSION_CODES.O)
150
152
  @Override
151
153
  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");
154
+ try {
155
+ mInterfaceUtil.rootDirectory = new File(cordova.getActivity().getExternalFilesDir(""), "");
156
+ if (mInterfaceUtil.packageName.equals("")) {
157
+ mInterfaceUtil.packageName = cordova.getActivity().getApplicationContext().getPackageName().split("\\.")[2];
168
158
  }
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();
159
+ if (action.equals("AppCleanUp")) {
160
+ mInterfaceUtil.appCleanUp(callbackContext, cordova.getActivity().getApplicationContext());
161
+ } else 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("Unable to StartService, Exception is: " + e.getMessage());
177
+ callbackContext.error("Unable to StartService, Exception is: " + 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.error("showToastWithOptions: "+ 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("unable to check location accuracy: Exception is: " + e.getMessage());
196
+ callbackContext.error("unable to check location accuracy: Exception is: " + 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("Unable to get Base 64 string: Exception is: " + e.getMessage());
204
+ callbackContext.error("Unable to get Base 64 string: Exception is: " + 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("GetFCMUtils: 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 */
424
+ try {
425
+ callbackContext.success(new mInterfaceUtil().getLocation(cordova.getActivity().getApplicationContext()));
426
+ } catch (Exception e) {
427
+ callbackContext.error(e.getMessage());
428
+ }
429
+ } else if (action.equals("CheckLocation")) {
430
+ /* SEND CURRENT LOCATION SETTING STATUS VIA PLUGIN CALLBACK */
431
+ try {
432
+ callbackContext.success(new mInterfaceUtil().checkLocation(cordova.getActivity().getApplicationContext()));
433
+ } catch (Exception e) {
434
+ callbackContext.error(e.getMessage());
435
+ }
436
+ } else if ("GetCurrentLocation".equals(action)) {
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")) {
430
451
  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) {
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("ReadFile failed, exception is : "+e.getMessage());
516
583
  }
517
- if (statusIndication.equals("true")) {
584
+ return true;
585
+ } else if (action.equals("DeleteFile")) {
586
+ new mInterfaceUtil().deleteFile(args, callbackContext);
587
+ return true;
588
+ } else if (action.equals("DeleteMultipleFiles")) {
589
+ System.out.println("args.length(): " + args.length());
590
+ for (int index = 0; index < args.length(); index++) {
591
+ String path = args.optString(index);
592
+ new mInterfaceUtil().deleteMultipleFiles(path, callbackContext);
593
+ }
594
+ callbackContext.success();
595
+ return true;
596
+ } else if (action.equals("CreateFile")) {
597
+ new mInterfaceUtil().createFile(args, callbackContext);
598
+ return true;
599
+ } else if (action.equals("ValidateFile")) {
600
+ new mInterfaceUtil().validateFile(args, callbackContext);
601
+ return true;
602
+ } else if (action.equals("CreateDirectory")) {
603
+ new mInterfaceUtil().createDirectory(args, callbackContext);
604
+ return true;
605
+ } else if (action.equals("DeleteDirectory")) {
606
+ new mInterfaceUtil().deleteDirectory(args, callbackContext);
607
+ return true;
608
+ } else if (action.equals("UploadFile")) {
609
+ String filePath = args.getJSONObject(0).optString("filePath");
610
+ String fileName = filePath.substring(filePath.lastIndexOf("/") + 1);
611
+ String url = args.getJSONObject(0).optString("url");
612
+ new mInterfaceUtil().sendFilesToServer(filePath, fileName, url);
613
+ return true;
614
+ } else if (action.equals("CopyFile")) {
615
+ arguments = args;
616
+ new mInterfaceUtil().copyFile(callbackContext, arguments);
617
+ } else if (action.equals("CopyAttachmentFile")) {
618
+ arguments = args;
619
+ new mInterfaceUtil().copyAttachmentFile(callbackContext, arguments);
620
+ } else if (action.equals("CopyConfigFile")) {
621
+ arguments = args;
622
+ new mInterfaceUtil().copyConfigFile(callbackContext, arguments);
623
+ } else if (action.equals("GetNewDate")) {
624
+ new mInterfaceUtil().getNewDate(callbackContext);
625
+ } else if (action.equals("RefreshTimeProfile")) {
626
+ JSONObject timeObj = args.getJSONObject(0);
627
+ String date, hour, minute;
628
+ date = timeObj.optString("serverDate");
629
+ hour = timeObj.optString("serverHour");
630
+ minute = timeObj.optString("serverMinute");
631
+ String returnStatus = new mInterfaceUtil().refreshTimeProfile(date, hour, minute);
632
+ if (returnStatus.equals("true")) {
518
633
  callbackContext.success("success");
519
634
  } else {
520
635
  callbackContext.error("failure");
521
636
  }
522
- } 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("UpdateNew failed, exception is : "+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("OpenFileWithViewer failed, exception is : "+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("CaptureImageFromCamera failed, exception is : "+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("PickImageFromGallery failed, exception is : "+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("DownloadFile failed for "+args.optJSONObject(0).optString("url")+", exception is : "+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("ScanQRCode failed, exception is : "+e.getMessage());
698
799
  }
699
- pickImageFromGallery(callbackContext);
800
+ } else if (action.equals("ScanBarCode")) {
801
+ try {
802
+ scanBarCode(callbackContext);
803
+ return true;
804
+ } catch (Exception e) {
805
+ callbackContext.error("ScanBarCode failed, exception is : "+e.getMessage());
806
+ }
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("GetAppStateInfo failed, exception is : "+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("UpdateAppInfo failed, exception is : "+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, "OpenSms failed, exception is : "+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, "OpenEmail failed, exception is : "+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, "copyAttachmentFile failed, exception is : "+e.getMessage());
962
+ callback.sendPluginResult(result);
963
+ }
896
964
 
965
+ }
966
+ } catch (JSONException e) {
967
+ System.out.println(" unable to proccess plugin method, exception is : "+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("scanQRCode failed, exception is : "+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("scanBarCode failed, exception is : "+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("getStorageRoot failed, exception is : "+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("getPermissions failed, exception is : "+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("pickImageFromGallery failed, exception is : "+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)
@@ -1246,191 +1352,27 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1246
1352
  File sourceFileObj = compressedImageFile;
1247
1353
  //** CHECK SOURCE FILE EXITS OR NOT **//
1248
1354
  if (sourceFileObj.exists()) {
1249
- srcFileReader = new FileInputStream(sourceFileObj);
1250
- desFileWriter = new FileOutputStream(new File(compressedImageName));
1251
- buf = new byte[1024];
1252
- //** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
1253
- while ((srcFileSize = srcFileReader.read(buf)) > 0) {
1254
- desFileWriter.write(buf, 0, srcFileSize);
1255
- }
1256
- srcFileReader.close();
1257
- desFileWriter.close();
1258
- }
1259
- bitmap = BitmapFactory.decodeFile(compressedImageName);
1260
-
1261
- } else {
1262
- bitmap = BitmapFactory.decodeFile(compressedImageFile.getAbsolutePath());
1263
- }
1264
- String encodedImage;
1265
- try {
1266
- ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1267
- bitmap.compress(Bitmap.CompressFormat.JPEG, 15, outputStream);
1268
- Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1269
- encodedImage = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1270
- if (imgSrcType.equals("camera")) {
1271
- File file = new File(imageSourcePath);
1272
- if (file.exists()) {
1273
- file.delete();
1274
- }
1275
- attachmentDestPath = "";
1276
- callbackContext.success(encodedImage);
1277
- } else if (imgSrcType.equals("gallery")) {
1278
- attachmentDestPath = "";
1279
- callbackContext.success(encodedImage);
1280
- } else if (imgSrcType.equals("compress")) {
1281
- try {
1282
-
1283
- if (!destinationPath.equalsIgnoreCase("")) {
1284
- File file = new File(imageSourcePath);
1285
- if (file.exists()) {
1286
- file.delete();
1287
- }
1288
- }
1289
- JSONObject fileProperities;
1290
- String imgFilePath, fileName, fileExtension;
1291
- imgFilePath = compressedImageName.substring(0, compressedImageName.lastIndexOf("/"));
1292
- String[] fileName1 = compressedImageName.split("/");
1293
- fileName = fileName1[fileName1.length - 1];
1294
- File file = new File(compressedImageName);
1295
- long fileSize = file.length();
1296
- fileExtension = "." + compressedImageName.substring(compressedImageName.lastIndexOf(".") + 1).toLowerCase();
1297
- fileProperities = new JSONObject();
1298
- fileProperities.put("filePath", imgFilePath);
1299
- fileProperities.put("fileName", fileName);
1300
- fileProperities.put("fileSize", fileSize);
1301
- fileProperities.put("fileExtension", fileExtension);
1302
- fileProperities.put("thumbnail", thumbnail);
1303
- attachmentDestPath = "";
1304
- callback.success(fileProperities);
1305
- } catch (Exception e) {
1306
- attachmentDestPath = "";
1307
- callback.error(e.getMessage());
1308
- }
1309
- }
1310
- } catch (Exception e) {
1311
- attachmentDestPath = "";
1312
- callbackContext.error(e.getMessage());
1313
- }
1314
-
1315
- } catch (IOException e) {
1316
- e.printStackTrace();
1317
- }
1318
-
1319
- }
1320
-
1321
-
1322
- public void convertImageTo64BaseString1(CallbackContext callbackContext, String imageSourcePath, String imgSrcType, String destinationPath) {
1323
- String compressedImagePathStr;
1324
- String compressedImageName = "";
1325
- String filePath = imageSourcePath;
1326
- Bitmap scaledBitmap = null;
1327
- BitmapFactory.Options options = new BitmapFactory.Options();
1328
- //by setting this field as true, the actual bitmap pixels are not loaded in the memory. Just the bounds are loaded. If
1329
- //you try the use the bitmap here, you will get null.
1330
- options.inJustDecodeBounds = true;
1331
- String[] bits = imageSourcePath.split("/");
1332
-
1333
- String fileNameToSend = bits[bits.length - 1];
1334
- if (fileNameToSend.indexOf(".") > 0)
1335
- fileNameToSend = fileNameToSend.substring(0, fileNameToSend.lastIndexOf("."));
1336
- Bitmap bmp = BitmapFactory.decodeFile(filePath, options);
1337
- int actualHeight = options.outHeight;
1338
- int actualWidth = options.outWidth;
1339
- //max Height and width values of the compressed image is taken as 816x612
1340
- float maxHeight = 816.0f;
1341
- float maxWidth = 612.0f;
1342
- float imgRatio = actualWidth / actualHeight;
1343
- float maxRatio = maxWidth / maxHeight;
1344
- //width and height values are set maintaining the aspect ratio of the image
1345
- if (actualHeight > maxHeight || actualWidth > maxWidth) {
1346
- if (imgRatio < maxRatio) {
1347
- imgRatio = maxHeight / actualHeight;
1348
- actualWidth = (int) (imgRatio * actualWidth);
1349
- actualHeight = (int) maxHeight;
1350
- } else if (imgRatio > maxRatio) {
1351
- imgRatio = maxWidth / actualWidth;
1352
- actualHeight = (int) (imgRatio * actualHeight);
1353
- actualWidth = (int) maxWidth;
1354
- } else {
1355
- actualHeight = (int) maxHeight;
1356
- actualWidth = (int) maxWidth;
1357
- }
1358
- }
1359
- options.inSampleSize = calculateInSampleSize(options, actualWidth, actualHeight);
1360
- options.inJustDecodeBounds = false;
1361
- //this options allow android to claim the bitmap memory if it runs low on memory
1362
- options.inPurgeable = true;
1363
- options.inInputShareable = true;
1364
- options.inTempStorage = new byte[16 * 1024];
1365
- try {
1366
- //load the bitmap from its path
1367
- bmp = BitmapFactory.decodeFile(filePath, options);
1368
- } catch (OutOfMemoryError exception) {
1369
- exception.printStackTrace();
1370
- }
1371
- try {
1372
- scaledBitmap = Bitmap.createBitmap(actualWidth, actualHeight, Bitmap.Config.ARGB_8888);
1373
- } catch (OutOfMemoryError exception) {
1374
- exception.printStackTrace();
1375
- }
1376
- float ratioX = actualWidth / (float) options.outWidth;
1377
- float ratioY = actualHeight / (float) options.outHeight;
1378
- float middleX = actualWidth / 2.0f;
1379
- float middleY = actualHeight / 2.0f;
1380
- Matrix scaleMatrix = new Matrix();
1381
- scaleMatrix.setScale(ratioX, ratioY, middleX, middleY);
1382
- Canvas canvas = new Canvas(scaledBitmap);
1383
- canvas.setMatrix(scaleMatrix);
1384
- canvas.drawBitmap(bmp, middleX - bmp.getWidth() / 2, middleY - bmp.getHeight() / 2, new Paint(Paint.FILTER_BITMAP_FLAG));
1385
- //check the rotation of the image and display it properly
1386
- ExifInterface exif;
1387
- try {
1388
- exif = new ExifInterface(filePath);
1389
- int orientation = exif.getAttributeInt(ExifInterface.TAG_ORIENTATION, 0);
1390
- Log.d("EXIF", "Exif: " + orientation);
1391
- Matrix matrix = new Matrix();
1392
- if (orientation == 6) {
1393
- matrix.postRotate(90);
1394
- Log.d("EXIF", "Exif: " + orientation);
1395
- } else if (orientation == 3) {
1396
- matrix.postRotate(180);
1397
- Log.d("EXIF", "Exif: " + orientation);
1398
- } else if (orientation == 8) {
1399
- matrix.postRotate(270);
1400
- Log.d("EXIF", "Exif: " + orientation);
1401
- }
1402
- scaledBitmap = Bitmap.createBitmap(scaledBitmap, 0, 0, scaledBitmap.getWidth(), scaledBitmap.getHeight(), matrix, true);
1403
- } catch (IOException e) {
1404
- e.printStackTrace();
1405
- }
1406
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
1407
- try {
1408
- if (imgSrcType.equals("compress")) {
1409
- String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1410
- if (!destinationPath.equalsIgnoreCase("")) {
1411
- compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + destinationPath;
1412
- } else {
1413
- compressedImagePathStr = mInterfaceUtil.rootDirectory + "/" + mInterfaceUtil.packageName + "/" + "images";
1414
- }
1415
- compressedImageName = compressedImagePathStr + "/" + fileNameToSend + "_" + timeStamp + ".jpg";
1416
- File fileSavedPath = new File(compressedImagePathStr);
1417
- if (!fileSavedPath.exists()) {
1418
- fileSavedPath.mkdirs();
1419
- }
1420
- FileOutputStream out = new FileOutputStream(compressedImageName);
1421
- if (scaledBitmap != null) {
1422
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, out);
1355
+ srcFileReader = new FileInputStream(sourceFileObj);
1356
+ desFileWriter = new FileOutputStream(new File(compressedImageName));
1357
+ buf = new byte[1024];
1358
+ //** WRITE SOURCE FILE INTO CONTENT_STORE DESTINATION PATH **//
1359
+ while ((srcFileSize = srcFileReader.read(buf)) > 0) {
1360
+ desFileWriter.write(buf, 0, srcFileSize);
1361
+ }
1362
+ srcFileReader.close();
1363
+ desFileWriter.close();
1423
1364
  }
1365
+ bitmap = BitmapFactory.decodeFile(compressedImageName);
1366
+
1424
1367
  } else {
1425
- if (scaledBitmap != null) {
1426
- scaledBitmap.compress(Bitmap.CompressFormat.JPEG, 30, baos);
1427
- }
1368
+ bitmap = BitmapFactory.decodeFile(compressedImageFile.getAbsolutePath());
1428
1369
  }
1429
1370
  String encodedImage;
1430
- byte[] byteArray;
1431
1371
  try {
1432
- byteArray = baos.toByteArray();
1433
- encodedImage = Base64.encodeToString(byteArray, Base64.NO_WRAP);
1372
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1373
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 15, outputStream);
1374
+ Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1375
+ encodedImage = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
1434
1376
  if (imgSrcType.equals("camera")) {
1435
1377
  File file = new File(imageSourcePath);
1436
1378
  if (file.exists()) {
@@ -1443,6 +1385,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1443
1385
  callbackContext.success(encodedImage);
1444
1386
  } else if (imgSrcType.equals("compress")) {
1445
1387
  try {
1388
+
1446
1389
  if (!destinationPath.equalsIgnoreCase("")) {
1447
1390
  File file = new File(imageSourcePath);
1448
1391
  if (file.exists()) {
@@ -1462,30 +1405,33 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1462
1405
  fileProperities.put("fileName", fileName);
1463
1406
  fileProperities.put("fileSize", fileSize);
1464
1407
  fileProperities.put("fileExtension", fileExtension);
1465
- fileProperities.put("thumbnail", getFileThumbnail(imgFilePath + "/" + fileName, fileExtension));
1408
+ fileProperities.put("thumbnail", thumbnail);
1466
1409
  attachmentDestPath = "";
1467
1410
  callback.success(fileProperities);
1468
1411
  } catch (Exception e) {
1469
1412
  attachmentDestPath = "";
1470
- callback.error(e.getMessage());
1413
+ callback.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
1471
1414
  }
1472
1415
  }
1473
1416
  } catch (Exception e) {
1474
1417
  attachmentDestPath = "";
1475
- callbackContext.error(e.getMessage());
1418
+ callbackContext.error("convertImageTo64BaseString failed, exception is : "+e.getMessage());
1476
1419
  }
1420
+
1477
1421
  } catch (Exception e) {
1478
1422
  e.printStackTrace();
1479
1423
  }
1424
+
1480
1425
  }
1481
1426
 
1482
1427
  public String getBase64String(String imageSourcePath) {
1483
1428
  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
1429
  try {
1430
+ String filePath = mInterfaceUtil.rootDirectory + "/" + imageSourcePath;
1431
+ File image = new File(filePath);
1432
+ BitmapFactory.Options bmOptions = new BitmapFactory.Options();
1433
+ Bitmap bitmap = BitmapFactory.decodeFile(image.getAbsolutePath(), bmOptions);
1434
+
1489
1435
  ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
1490
1436
  bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
1491
1437
  resultString = Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
@@ -1504,23 +1450,28 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1504
1450
  pluginResult.setKeepCallback(true);
1505
1451
  callbackContext.sendPluginResult(pluginResult);
1506
1452
  } catch (Exception e) {
1507
- callbackContext.error(e.getMessage());
1453
+ callbackContext.error("unable to choose file, exception is : "+e.getMessage());
1508
1454
  }
1509
1455
  }
1510
1456
 
1511
1457
  public Intent getPickImageChooserIntent() {
1512
1458
  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);
1459
+ try {
1460
+ if (Build.MANUFACTURER.equals("samsung")) {
1461
+ openFile = new Intent("com.sec.android.app.myfiles.PICK_DATA");
1462
+ openFile.putExtra("CONTENT_TYPE", "*/*");
1463
+ } else {
1464
+ openFile = new Intent(Intent.ACTION_GET_CONTENT);
1465
+ openFile.setType("*/*");
1466
+ openFile.addCategory(Intent.CATEGORY_OPENABLE);
1467
+ openFile.putExtra(Intent.EXTRA_LOCAL_ONLY, true);
1468
+ }
1469
+ selectFile = Intent.createChooser(openFile, "Select File");
1470
+ return selectFile;
1471
+ } catch (Exception e) {
1472
+ e.printStackTrace();
1521
1473
  }
1522
- selectFile = Intent.createChooser(openFile, "Select File");
1523
- return selectFile;
1474
+ return null;
1524
1475
  }
1525
1476
 
1526
1477
  //App version plugin
@@ -1528,299 +1479,319 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1528
1479
  try {
1529
1480
  PackageManager packageManager = this.cordova.getActivity().getPackageManager();
1530
1481
  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
- }
1482
+ r.put("version", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionName);
1483
+ r.put("build", packageManager.getPackageInfo(this.cordova.getActivity().getPackageName(), 0).versionCode);
1537
1484
  callbackContext.success(r);
1538
- } catch (PackageManager.NameNotFoundException e) {
1539
- callbackContext.error("Exception thrown");
1485
+ } catch (Exception e) {
1486
+ callbackContext.error("unable to get appVersion, exception is : "+e.getMessage());
1540
1487
  }
1541
1488
  }
1542
1489
 
1543
1490
  //Rotate Screen plugin
1544
1491
  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);
1492
+ try {
1493
+ String orientation = args.optString(0);
1494
+ String currentOrientation;
1495
+ Activity activity = cordova.getActivity();
1496
+ int orientation1 = activity.getResources().getConfiguration().orientation;
1497
+ if (orientation1 == Configuration.ORIENTATION_LANDSCAPE) {
1498
+ currentOrientation = "landscape";
1499
+ } else {
1500
+ currentOrientation = "portrait";
1501
+ }
1502
+ if (orientation.equals(ANY)) {
1503
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
1504
+ } else if (orientation.equals(LANDSCAPE_PRIMARY)) {
1505
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
1506
+ } else if (orientation.equals(PORTRAIT_PRIMARY)) {
1507
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
1508
+ } else if (orientation.equals(LANDSCAPE)) {
1509
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
1510
+ } else if (orientation.equals(PORTRAIT)) {
1511
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
1512
+ } else if (orientation.equals(LANDSCAPE_SECONDARY)) {
1513
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE);
1514
+ } else if (orientation.equals(PORTRAIT_SECONDARY)) {
1515
+ activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT);
1516
+ }
1517
+ callbackContext.success(currentOrientation);
1518
+ } catch (Exception e) {
1519
+ callbackContext.success("rotateScreen failed, exception is : "+e.getMessage());
1568
1520
  }
1569
- callbackContext.success(currentOrientation);
1570
1521
  }
1571
1522
 
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);
1523
+ public void deviceInfo(CallbackContext callbackContext) {
1524
+ try {
1525
+ String uuid = Settings.Secure.getString(this.cordova.getActivity().getContentResolver(), Settings.Secure.ANDROID_ID);
1526
+ JSONObject r = new JSONObject();
1527
+ boolean a = Build.FINGERPRINT.contains("generic") ||
1528
+ Build.PRODUCT.contains("sdk");
1529
+ @SuppressWarnings("deprecation")
1530
+ String sdkversion = Build.VERSION.SDK;
1531
+ r.put("uuid", uuid);
1532
+ r.put("version", Build.VERSION.RELEASE);
1533
+ r.put("platform", ANDROID_PLATFORM);
1534
+ r.put("model", Build.MODEL);
1535
+ r.put("manufacturer", Build.MANUFACTURER);
1536
+ r.put("isVirtual", a);
1537
+ r.put("serial", Build.SERIAL);
1538
+ r.put("timeZone", TimeZone.getDefault());
1539
+ r.put("sdkVersion", sdkversion);
1540
+ r.put("productName", Build.PRODUCT);
1541
+ r.put("applicationName", getApplicationName(cordova.getActivity()));
1542
+ callbackContext.success(r);
1543
+ } catch (Exception e) {
1544
+ callbackContext.error("unable to get deviceInfo, exception is : "+e.getMessage());
1545
+ }
1591
1546
  }
1592
1547
 
1593
1548
  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);
1549
+ try {
1550
+ ApplicationInfo applicationInfo = context.getApplicationInfo();
1551
+ int stringId = applicationInfo.labelRes;
1552
+ return stringId == 0 ? applicationInfo.nonLocalizedLabel.toString() : context.getString(stringId);
1553
+ } catch (Exception e) {
1554
+ e.printStackTrace();
1555
+ }
1556
+ return "";
1597
1557
  }
1598
1558
 
1599
1559
  @Override
1600
1560
  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);
1561
+ try {
1562
+ switch (requestCode) {
1563
+ case LOCATION_ACCURACY_REQUEST_NEW:
1564
+ switch (resultCode) {
1565
+ case Activity.RESULT_OK:
1566
+ mInterfaceService mInterfaceService = new mInterfaceService();
1567
+ mInterfaceService.startLocationUpdates(cordova.getContext());
1568
+ callback.success();
1569
+ break;
1570
+ case Activity.RESULT_CANCELED:
1571
+ callback.error("oops! you have cancelled...");
1572
+ break;
1573
+ }
1574
+ break;
1638
1575
  }
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;
1576
+ if (SCANCODEINT == 118 && callback != null) {
1577
+ if (resultCode == RESULT_OK) {
1578
+ SCANCODEINT = 0;
1579
+ IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
1580
+ callback.success(result.getContents());
1581
+ } else if (resultCode == Activity.RESULT_CANCELED) {
1582
+ SCANCODEINT = 0;
1583
+ callback.error("canceled");
1584
+ } else {
1585
+ SCANCODEINT = 0;
1586
+ callback.error(resultCode);
1587
+ }
1588
+ } else if (SCANCODEINT == 119 && callback != null) {
1589
+ if (resultCode == RESULT_OK) {
1590
+ SCANCODEINT = 0;
1591
+ IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, data);
1592
+ callback.success(result.getContents());
1593
+ } else if (resultCode == Activity.RESULT_CANCELED) {
1594
+ SCANCODEINT = 0;
1595
+ callback.error("canceled");
1596
+ } else {
1597
+ SCANCODEINT = 0;
1598
+ callback.error(resultCode);
1599
+ }
1600
+ } else if (requestCode == PICK_IMAGE_FROM_GALLERY && callback != null) {
1601
+ if (resultCode == RESULT_OK) {
1602
+ String fileName = null, getfilePath = null, filePath, fileType, storageDefinition, fileExtension;
1603
+ final String docId, type, id;
1604
+ final String[] split;
1605
+ final String tag, path;
1606
+ final int splitIndex;
1607
+ Cursor cursor;
1608
+ Uri uri = data.getData(); //get uri for selected file
1609
+ fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
1610
+ File getFileName, file;
1611
+ try {
1612
+ //API LEVEL 19 AND ABOVE (TO GET FILEPATH)
1613
+ if (Build.VERSION.SDK_INT >= 19 && !Build.MANUFACTURER.equals("samsung") && DocumentsContract.isDocumentUri(cordova.getActivity(), uri)) {
1614
+ if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { // ExternalStorageProvider
1615
+ docId = DocumentsContract.getDocumentId(uri);
1616
+ split = docId.split(":");
1617
+ type = split[0];
1618
+ if ("primary".equalsIgnoreCase(type)) {
1619
+ getfilePath = mInterfaceUtil.rootDirectory + "/" + split[1];
1663
1620
  } 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;
1621
+ if (Environment.isExternalStorageRemovable()) {
1622
+ storageDefinition = System.getenv("EXTERNAL_STORAGE");
1623
+ getfilePath = storageDefinition;
1624
+ } else {
1625
+ splitIndex = docId.indexOf(':', 1);
1626
+ tag = docId.substring(0, splitIndex);
1627
+ path = docId.substring(splitIndex + 1);
1628
+ if (new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) != null) {
1629
+ storageDefinition = new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) + "/" + path;
1630
+ file = new File(storageDefinition);
1631
+ if (file.exists() && file.canRead()) {
1632
+ getfilePath = storageDefinition;
1633
+ }
1672
1634
  }
1673
1635
  }
1674
1636
  }
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 = "";
1637
+ } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { // DownloadsProvider
1638
+ id = DocumentsContract.getDocumentId(uri);
1639
+ final Uri contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
1640
+ getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, null, null);
1641
+ } else if ("com.android.providers.media.documents".equals(uri.getAuthority())) { // MediaProvider
1642
+ docId = DocumentsContract.getDocumentId(uri);
1643
+ split = docId.split(":");
1644
+ type = split[0];
1645
+ Uri contentUri = null;
1646
+ if ("image".equals(type)) {
1647
+ contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
1648
+ } else if ("video".equals(type)) {
1649
+ contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
1650
+ } else if ("audio".equals(type)) {
1651
+ contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
1707
1652
  }
1653
+ final String selection = "_id=?";
1654
+ final String[] selectionArgs = new String[]{
1655
+ split[1]
1656
+ };
1657
+ getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
1708
1658
  }
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));
1659
+ // *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
1660
+ cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
1661
+ try {
1662
+ if (cursor != null && cursor.moveToFirst()) {
1663
+ int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
1664
+ if (displayNameIndex != -1) {
1665
+ fileName = cursor.getString(displayNameIndex);
1666
+ } else {
1667
+ fileName = "";
1668
+ }
1669
+ }
1670
+ } finally {
1671
+ cursor.close();
1724
1672
  }
1725
- cursor.close();
1726
- // API LEVEL 19 BELOW AND SAMSUNG (TO GET FILE PROPERTIES OF NORMAL FILES(EX:txt,.pdf,etc..,))
1673
+ // *** API Level 19 below and SAMSUNG (To Get FileProperties of MediaFiles)**** //
1727
1674
  } 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", "");
1675
+ if (fileType != null) {
1676
+ String[] projection = {
1677
+ MediaStore.Images.Media.DATA,
1678
+ MediaStore.Images.Media.SIZE,
1679
+ MediaStore.Images.Media.DISPLAY_NAME
1680
+ };
1681
+ cursor = cordova.getActivity().getContentResolver().query(uri, projection, null, null, null);
1682
+ if (cursor.moveToFirst()) {
1683
+ getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
1684
+ fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
1743
1685
  }
1686
+ cursor.close();
1687
+ // API LEVEL 19 BELOW AND SAMSUNG (TO GET FILE PROPERTIES OF NORMAL FILES(EX:txt,.pdf,etc..,))
1688
+ } else {
1689
+ getfilePath = data.getData().getPath();
1690
+ filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
1691
+ getFileName = new File(getfilePath);
1692
+ fileName = getFileName.getName();
1693
+ }
1694
+ }
1695
+ filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
1696
+ fileExtension = "." + getfilePath.substring(getfilePath.lastIndexOf(".") + 1).toLowerCase();
1697
+ if (filePath != null) {
1698
+ try {
1699
+ if (fileExtension.equals(".heic")) {
1700
+ if (galleryAttachmentInd.equals("true")) {
1701
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1702
+ } else {
1703
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
1704
+ }
1744
1705
 
1745
- } else if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
1746
- if (galleryAttachmentInd.equals("true")) {
1747
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1706
+ } else if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
1707
+ if (galleryAttachmentInd.equals("true")) {
1708
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1709
+ } else {
1710
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
1711
+ }
1748
1712
  } else {
1749
- convertImageTo64BaseString(callback, filePath + "/" + fileName, "gallery", "");
1713
+ callback.error("Only JPEG or PNG file extensions are allowed to attach.");
1750
1714
  }
1751
- } else {
1715
+ } catch (Exception e) {
1752
1716
  callback.error("Only JPEG or PNG file extensions are allowed to attach.");
1753
1717
  }
1754
- } catch (Exception e) {
1755
- callback.error("Only JPEG or PNG file extensions are allowed to attach.");
1718
+ } else {
1719
+ callback.error("File path was null");
1756
1720
  }
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;
1721
+ } catch (Exception e) {
1722
+ e.printStackTrace();
1781
1723
  }
1724
+ } else if (resultCode == Activity.RESULT_CANCELED) {
1725
+ callback.error("failure");
1782
1726
  } 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);
1727
+ callback.error(resultCode);
1728
+ }
1729
+ } else if (requestCode == NEW_FILE_PICK_REQUEST && callback != null) {
1730
+ try {
1731
+ Uri uri = data.getData();
1732
+ String fileName, extension, filePath;
1733
+ JSONObject fileProperities;
1734
+ Cursor cursor = null;
1735
+ if (uri.getScheme().equals("file")) {
1736
+ fileName = uri.getLastPathSegment();
1737
+ if (fileName.indexOf(".") > 0) {
1738
+ fileName = fileName.substring(0, fileName.lastIndexOf("."));
1739
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1740
+ extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1741
+ fileName = fileName + "_" + timeStamp + extension;
1742
+ }
1743
+ } else {
1744
+ try {
1745
+ cursor = cordova.getActivity().getApplicationContext().getContentResolver().query(uri, new String[]{MediaStore.Images.ImageColumns.DISPLAY_NAME}, null, null, null);
1746
+ if (cursor != null && cursor.moveToFirst()) {
1747
+ int displayNameIndex = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DISPLAY_NAME);
1748
+ if (displayNameIndex != -1) {
1749
+ fileName = cursor.getString(displayNameIndex);
1750
+ } else {
1751
+ fileName = "";
1752
+ }
1753
+ extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1754
+ if (!extension.equals(".jpeg") && !extension.equals(".jpg") && !extension.equals(".png")) {
1755
+ String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
1756
+ fileName = fileName.substring(0, fileName.lastIndexOf("."));
1757
+ fileName = fileName + "_" + timeStamp + extension;
1758
+ }
1759
+
1789
1760
  } else {
1790
- fileName = "";
1761
+ fileName = uri.getLastPathSegment();
1791
1762
  }
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;
1763
+ } finally {
1764
+ if (cursor != null) {
1765
+ cursor.close();
1797
1766
  }
1798
-
1799
- } else {
1800
- fileName = uri.getLastPathSegment();
1801
- }
1802
- } finally {
1803
- if (cursor != null) {
1804
- cursor.close();
1805
1767
  }
1806
1768
  }
1807
- }
1808
1769
 
1809
- extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1770
+ extension = "." + fileName.substring(fileName.lastIndexOf(".") + 1).toLowerCase();
1810
1771
 
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")) {
1772
+ filePath = copyFileFromUri(cordova.getActivity().getApplicationContext(), uri, fileName, attachmentDestPath, callback);
1773
+ File file = new File(filePath);
1774
+ String mimeType = getMimeType(filePath, uri);
1775
+ System.out.println("Mime type is: " + mimeType);
1776
+ double fileSize = file.length();
1777
+ if (filePath != null) {
1778
+ try {
1779
+ if (requestCode == NEW_FILE_PICK_REQUEST) {
1780
+ if (extension.equals(".heic")) {
1823
1781
  convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
1782
+ } else if (mimeType != null) {
1783
+ if (mimeType.contains("image")) {
1784
+ convertImageTo64BaseString(callback, filePath, "compress", attachmentDestPath);
1785
+ } else {
1786
+ fileProperities = new JSONObject();
1787
+ fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
1788
+ fileProperities.put("fileName", fileName);
1789
+ fileProperities.put("fileSize", fileSize);
1790
+ fileProperities.put("fileExtension", extension);
1791
+ fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
1792
+ attachmentDestPath = "";
1793
+ callback.success(fileProperities);
1794
+ }
1824
1795
  } else {
1825
1796
  fileProperities = new JSONObject();
1826
1797
  fileProperities.put("filePath", filePath.substring(0, filePath.lastIndexOf(File.separator)));
@@ -1828,207 +1799,200 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
1828
1799
  fileProperities.put("fileSize", fileSize);
1829
1800
  fileProperities.put("fileExtension", extension);
1830
1801
  fileProperities.put("thumbnail", getFileThumbnail(filePath, extension));
1831
- attachmentDestPath = "";
1832
1802
  callback.success(fileProperities);
1833
1803
  }
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
1804
  }
1805
+ } catch (Exception e) {
1806
+ callback.error("onActivityResult failed, exception is : "+e.getMessage());
1843
1807
  }
1844
- } catch (Exception e) {
1845
- callback.error(e.getMessage());
1808
+ } else {
1809
+ callback.error("onActivityResult: Selected file path is null");
1810
+ }
1811
+ } catch (Exception e) {
1812
+ callback.error("onActivityResult failed, exception is : "+e.getMessage());
1813
+ }
1814
+ } else if (requestCode == REQUEST_IMAGE_CAPTURE && callback != null) {
1815
+ if (resultCode == RESULT_OK) {
1816
+ if (cameraAttachmentInd.equals("true")) {
1817
+ convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
1818
+ } else {
1819
+ convertImageTo64BaseString(callback, pictureFilePath, "camera", "");
1820
+ }
1821
+
1822
+ } else if (resultCode == Activity.RESULT_CANCELED) {
1823
+ File file = new File(pictureFilePath);
1824
+ if (file.exists()) {
1825
+ file.delete();
1846
1826
  }
1827
+ callback.error("failure");
1847
1828
  } else {
1848
- callback.error("Selected file path is null");
1829
+ callback.error(resultCode);
1849
1830
  }
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")) {
1831
+ } else if (requestCode == REQUEST_LIVE_IMAGE_CAPTURE && callback != null) {
1832
+ if (resultCode == RESULT_OK) {
1856
1833
  convertImageTo64BaseString(callback, pictureFilePath, "compress", attachmentDestPath);
1834
+ } else if (resultCode == Activity.RESULT_CANCELED) {
1835
+ File file = new File(pictureFilePath);
1836
+ if (file.exists()) {
1837
+ file.delete();
1838
+ }
1839
+ callback.error("failure");
1857
1840
  } else {
1858
- convertImageTo64BaseString(callback, pictureFilePath, "camera", "");
1859
- }
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();
1841
+ callback.error(resultCode);
1877
1842
  }
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;
1843
+ } else if (requestCode == PICK_FILE_REQUEST && callback != null) {
1844
+ if (resultCode == RESULT_OK) {
1845
+ String fileName = null,
1846
+ getfilePath = null,
1847
+ filePath,
1848
+ fileExtension,
1849
+ fileType,
1850
+ fileSize = null,
1851
+ storageDefinition;
1852
+ final String docId,
1853
+ type,
1854
+ id;
1855
+ final String[] split;
1856
+ final String tag,
1857
+ path;
1858
+ final int splitIndex;
1859
+ Cursor cursor;
1860
+ long getSize;
1861
+ JSONObject fileProperities;
1862
+ Uri uri = data.getData(); //get uri for selected file
1863
+ fileType = this.cordova.getActivity().getContentResolver().getType(uri); // get mimeType for selected file
1864
+ File getFileName,
1865
+ file;
1866
+ try {
1867
+ //API LEVEL 19 AND ABOVE (TO GET FILEPATH)
1868
+ if (Build.VERSION.SDK_INT >= 19 && !Build.MANUFACTURER.equals("samsung") && DocumentsContract.isDocumentUri(cordova.getActivity(), uri)) {
1869
+ if ("com.android.externalstorage.documents".equals(uri.getAuthority())) { // ExternalStorageProvider
1870
+ docId = DocumentsContract.getDocumentId(uri);
1871
+ split = docId.split(":");
1872
+ type = split[0];
1873
+ if ("primary".equalsIgnoreCase(type)) {
1874
+ getfilePath = mInterfaceUtil.rootDirectory + "/" + split[1];
1918
1875
  } 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;
1876
+ if (Environment.isExternalStorageRemovable()) {
1877
+ storageDefinition = System.getenv("EXTERNAL_STORAGE");
1878
+ getfilePath = storageDefinition;
1879
+ } else {
1880
+ splitIndex = docId.indexOf(':', 1);
1881
+ tag = docId.substring(0, splitIndex);
1882
+ path = docId.substring(splitIndex + 1);
1883
+ if (new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) != null) {
1884
+ storageDefinition = new mInterfaceUtil().getPathToNonPrimaryVolume(cordova.getActivity(), tag) + "/" + path;
1885
+ file = new File(storageDefinition);
1886
+ if (file.exists() && file.canRead()) {
1887
+ getfilePath = storageDefinition;
1888
+ }
1927
1889
  }
1928
1890
  }
1929
1891
  }
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 = "";
1892
+ } else if ("com.android.providers.downloads.documents".equals(uri.getAuthority())) { // DownloadsProvider
1893
+ id = DocumentsContract.getDocumentId(uri);
1894
+ final Uri contentUri = ContentUris.withAppendedId(
1895
+ Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
1896
+ getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, null, null);
1897
+
1898
+ } else if ("com.android.providers.media.documents".equals(uri.getAuthority())) { // MediaProvider
1899
+ docId = DocumentsContract.getDocumentId(uri);
1900
+ split = docId.split(":");
1901
+ type = split[0];
1902
+ Uri contentUri = null;
1903
+ if ("image".equals(type)) {
1904
+ contentUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
1905
+ } else if ("video".equals(type)) {
1906
+ contentUri = MediaStore.Video.Media.EXTERNAL_CONTENT_URI;
1907
+ } else if ("audio".equals(type)) {
1908
+ contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
1964
1909
  }
1910
+ final String selection = "_id=?";
1911
+ final String[] selectionArgs = new String[]{
1912
+ split[1]
1913
+ };
1914
+ getfilePath = new mInterfaceUtil().getDataColumn(cordova.getActivity(), contentUri, selection, selectionArgs);
1915
+ }
1916
+ // *** API Level 19 and Above (To Get FileName,FileExtension and FileSize)**** //
1917
+ cursor = cordova.getActivity().getContentResolver().query(uri, null, null, null, null, null);
1918
+ try {
1919
+ if (cursor != null && cursor.moveToFirst()) {
1920
+ int displayNameIndex = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
1921
+ if (displayNameIndex != -1) {
1922
+ fileName = cursor.getString(displayNameIndex);
1923
+ } else {
1924
+ fileName = "";
1925
+ }
1965
1926
 
1966
- int fileSizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
1967
- if (!cursor.isNull(fileSizeIndex) && fileSizeIndex != -1) {
1968
- fileSize = cursor.getString(fileSizeIndex);
1969
- } else {
1970
- fileSize = "0";
1927
+ int fileSizeIndex = cursor.getColumnIndex(OpenableColumns.SIZE);
1928
+ if (!cursor.isNull(fileSizeIndex) && fileSizeIndex != -1) {
1929
+ fileSize = cursor.getString(fileSizeIndex);
1930
+ } else {
1931
+ fileSize = "0";
1932
+ }
1971
1933
  }
1934
+ } finally {
1935
+ cursor.close();
1972
1936
  }
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..,))
1937
+ // *** API Level 19 below and SAMSUNG (To Get FileProperties of MediaFiles)**** //
1992
1938
  } 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);
1939
+ if (fileType != null) {
1940
+ String[] projection = {
1941
+ MediaStore.Images.Media.DATA,
1942
+ MediaStore.Images.Media.SIZE,
1943
+ MediaStore.Images.Media.DISPLAY_NAME
1944
+ };
1945
+ cursor = cordova.getActivity().getContentResolver().query(uri, projection, null, null, null);
1946
+ if (cursor.moveToFirst()) {
1947
+ getfilePath = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA));
1948
+ fileName = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DISPLAY_NAME));
1949
+ fileSize = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Images.Media.SIZE));
1950
+ }
1951
+ cursor.close();
1952
+ // API LEVEL 19 BELOW AND SAMSUNG (TO GET FILEPROPERTIES OF NORMAL FILES(EX:txt,.pdf,etc..,))
2008
1953
  } 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);
1954
+ getfilePath = data.getData().getPath();
1955
+ filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
1956
+ getFileName = new File(getfilePath);
1957
+ fileName = getFileName.getName();
1958
+ getSize = getFileName.length();
1959
+ fileSize = String.valueOf(getSize);
2015
1960
  }
2016
- } catch (Exception e) {
2017
- callback.error("Failed to process PICK_FILE_REQUEST");
2018
1961
  }
2019
- } else {
2020
- callback.error("File path was null");
1962
+ filePath = getfilePath.substring(0, getfilePath.lastIndexOf(File.separator));
1963
+ fileExtension = "." + getfilePath.substring(getfilePath.lastIndexOf(".") + 1).toLowerCase();
1964
+ // SEND BELOW JSON OBJECT TO PLUGIN CALLBACK
1965
+ if (filePath != null) {
1966
+ try {
1967
+ if (fileExtension.equals(".jpeg") || fileExtension.equals(".jpg") || fileExtension.equals(".png")) {
1968
+ convertImageTo64BaseString(callback, filePath + "/" + fileName, "compress", attachmentDestPath);
1969
+ } else {
1970
+ fileProperities = new JSONObject();
1971
+ fileProperities.put("filePath", filePath);
1972
+ fileProperities.put("fileName", fileName);
1973
+ fileProperities.put("fileSize", fileSize);
1974
+ fileProperities.put("fileExtension", fileExtension);
1975
+ callback.success(fileProperities);
1976
+ }
1977
+ } catch (Exception e) {
1978
+ callback.error("Failed to process PICK_FILE_REQUEST");
1979
+ }
1980
+ } else {
1981
+ callback.error("File path was null");
1982
+ }
1983
+ } catch (Exception e) {
1984
+ e.printStackTrace();
2021
1985
  }
2022
- } catch (Exception e) {
2023
- e.printStackTrace();
1986
+ } else if (resultCode == Activity.RESULT_CANCELED) {
1987
+ callback.error("failure");
1988
+ } else {
1989
+ callback.error(resultCode);
2024
1990
  }
2025
- } else if (resultCode == Activity.RESULT_CANCELED) {
2026
- callback.error("failure");
2027
1991
  } else {
2028
- callback.error(resultCode);
1992
+ callback.error("failure");
2029
1993
  }
2030
- } else {
2031
- callback.error("failure");
1994
+ } catch (Exception e) {
1995
+ e.printStackTrace();
2032
1996
  }
2033
1997
  }
2034
1998
 
@@ -2087,55 +2051,72 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2087
2051
  callback.error("Error occurred in opening outputStream");
2088
2052
  }
2089
2053
  } catch (Exception e) {
2090
- callback.error("Exception occurred " + e.getMessage());
2054
+ callback.error("copyFileFromUri failed, exception is : "+e.getMessage());
2091
2055
  }
2092
2056
  return outPutFilePath;
2093
2057
  }
2094
2058
 
2095
2059
  /* CHECKING THE BACKGROUND SERVICE RUNNING OR NOT */
2096
2060
  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;
2061
+ try {
2062
+ ActivityManager manager = (ActivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
2063
+ for (ActivityManager.RunningServiceInfo service : manager.getRunningServices(Integer.MAX_VALUE)) {
2064
+ if (serviceClass.getName().equals(service.service.getClassName())) {
2065
+ return true;
2066
+ }
2101
2067
  }
2068
+
2069
+ } catch (SecurityException e) {
2070
+ e.printStackTrace();
2102
2071
  }
2103
2072
  return false;
2104
2073
  }
2105
2074
 
2106
2075
  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;
2076
+ try {
2077
+ ActivityManager manager1 = (ActivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.ACTIVITY_SERVICE);
2078
+ for (ActivityManager.RunningAppProcessInfo processInfo : manager1.getRunningAppProcesses()) {
2079
+ if (processInfo.processName.equals(cordova.getActivity().getPackageName())) {
2080
+ return true;
2081
+ }
2111
2082
  }
2083
+ } catch (Exception e) {
2084
+ e.printStackTrace();
2112
2085
  }
2113
2086
  return false;
2114
2087
  }
2115
2088
 
2116
2089
  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);
2090
+ try {
2091
+ callback = callbackContext;
2092
+ createLocationRequest1();
2093
+ mGoogleApiClient1 = new GoogleApiClient.Builder(cordova.getActivity())
2094
+ .addApi(LocationServices.API).addConnectionCallbacks(this)
2095
+ .addOnConnectionFailedListener(this).build();
2096
+ mGoogleApiClient1.connect();
2097
+ LocationRequest locationRequest = LocationRequest.create();
2098
+ locationRequest.setPriority(Priority.PRIORITY_HIGH_ACCURACY);
2099
+ locationRequest.setInterval(30 * 1000);
2100
+ locationRequest.setFastestInterval(5 * 1000);
2101
+ LocationSettingsRequest.Builder builder = new LocationSettingsRequest.Builder()
2102
+ .addLocationRequest(locationRequest);
2103
+ builder.setAlwaysShow(true); // this is the key ingredient
2104
+ PendingResult<LocationSettingsResult> result = LocationServices.SettingsApi
2105
+ .checkLocationSettings(mGoogleApiClient1, builder.build());
2106
+ result.setResultCallback(this);
2107
+ } catch (Exception e) {
2108
+ callbackContext.error("EnableGPSAutomatically failed, exception is : "+e.getMessage());
2109
+ }
2133
2110
  }
2134
2111
 
2135
2112
  @Override
2136
2113
  public void onConnected(@Nullable Bundle bundle) {
2137
- if (mGoogleApiClient1.isConnected()) {
2138
- startLocationUpdates1();
2114
+ try {
2115
+ if (mGoogleApiClient1.isConnected()) {
2116
+ startLocationUpdates1();
2117
+ }
2118
+ } catch (Exception e) {
2119
+ System.out.println("GoogleApiClient failed, exception is : "+e.getMessage());
2139
2120
  }
2140
2121
  }
2141
2122
 
@@ -2149,21 +2130,25 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2149
2130
 
2150
2131
  @Override
2151
2132
  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;
2133
+ try {
2134
+ final Status status = locationSettingsResult.getStatus();
2135
+ switch (status.getStatusCode()) {
2136
+ case LocationSettingsStatusCodes.SUCCESS:
2137
+ break;
2138
+ case LocationSettingsStatusCodes.RESOLUTION_REQUIRED:
2139
+ try {
2140
+ this.cordova.setActivityResultCallback(this);
2141
+ status.startResolutionForResult(this.cordova.getActivity(), LOCATION_ACCURACY_REQUEST_NEW);
2142
+ } catch (IntentSender.SendIntentException e) {
2143
+ System.out.println("PendingIntent unable to execute request: ");
2144
+ }
2145
+ break;
2146
+ case LocationSettingsStatusCodes.SETTINGS_CHANGE_UNAVAILABLE:
2147
+ System.out.println("Location settings are inadequate, and cannot be fixed here. Dialog not created.");
2148
+ break;
2149
+ }
2150
+ } catch (Exception e) {
2151
+ System.out.println("LocationSettingsResult failed, exception is : "+e.getMessage());
2167
2152
  }
2168
2153
  }
2169
2154
 
@@ -2177,7 +2162,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2177
2162
  callback.success(mCurrentLocation1.getLatitude() + "," + mCurrentLocation1.getLongitude());
2178
2163
  }
2179
2164
  } catch (Exception e) {
2180
- callback.error(e.getMessage());
2165
+ callback.error("onLocationChanged failed, exception is : "+e.getMessage());
2181
2166
  }
2182
2167
  }
2183
2168
 
@@ -2233,7 +2218,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2233
2218
  output.write(data, 0, count);
2234
2219
  }
2235
2220
  } catch (Exception e) {
2236
- downloadFileCallback.error("Failure..." + e.getMessage());
2221
+ downloadFileCallback.error("DownloadTask failed for url"+sUrl[0]+" , exception is : "+e.getMessage());
2237
2222
  }
2238
2223
  if (sUrl[2].equalsIgnoreCase("true")) {
2239
2224
  return sUrl[1];
@@ -2252,29 +2237,38 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2252
2237
  String thumbnail = getFileThumbnail(filePath, extension);
2253
2238
  downloadFileCallback.success(thumbnail);
2254
2239
  } else {
2255
- downloadFileCallback.error("Failure...");
2240
+ downloadFileCallback.error("Failure");
2256
2241
  }
2257
2242
  } else {
2258
2243
  System.out.println("success");
2259
2244
  downloadFileCallback.success("");
2260
2245
  }
2261
2246
  } catch (Exception e) {
2262
- e.printStackTrace();
2247
+ downloadFileCallback.error("copyAttachmentFile failed, exception is : "+e.getMessage());
2263
2248
  }
2264
2249
  }
2265
2250
  }
2266
2251
 
2267
2252
  public static String pathComponent(String filename) {
2268
- int i = filename.lastIndexOf(File.separator);
2269
- return (i > -1) ? filename.substring(0, i) : filename;
2253
+ try {
2254
+ int i = filename.lastIndexOf(File.separator);
2255
+ return (i > -1) ? filename.substring(0, i) : filename;
2256
+ } catch (Exception e) {
2257
+ e.printStackTrace();
2258
+ }
2259
+ return "";
2270
2260
  }
2271
2261
 
2272
2262
  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
- });
2263
+ try {
2264
+ this.cordova.getThreadPool().execute(new Runnable() {
2265
+ public void run() {
2266
+ unzipSync(args, callbackContext);
2267
+ }
2268
+ });
2269
+ } catch (Exception e) {
2270
+ e.printStackTrace();
2271
+ }
2278
2272
  }
2279
2273
 
2280
2274
  private void unzipSync(JSONArray args, CallbackContext callbackContext) {
@@ -2347,7 +2341,7 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2347
2341
  else
2348
2342
  callbackContext.error("Bad zip file");
2349
2343
  } catch (Exception e) {
2350
- String errorMessage = "An error occurred while unzipping.";
2344
+ String errorMessage = "unzipSync failed, exception is : "+e.getMessage();
2351
2345
  callbackContext.error(errorMessage);
2352
2346
  } finally {
2353
2347
  if (inputStream != null) {
@@ -2377,9 +2371,14 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2377
2371
 
2378
2372
 
2379
2373
  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();
2374
+ try {
2375
+ ConnectivityManager online = (ConnectivityManager) cordova.getActivity().getApplicationContext().getSystemService(Context.CONNECTIVITY_SERVICE);
2376
+ NetworkInfo networkInfo = online.getActiveNetworkInfo();
2377
+ return networkInfo != null && networkInfo.isConnected();
2378
+ } catch (Exception e) {
2379
+ e.printStackTrace();
2380
+ }
2381
+ return false;
2383
2382
  }
2384
2383
 
2385
2384
 
@@ -2415,8 +2414,13 @@ public class mInterface extends CordovaPlugin implements com.google.android.gms.
2415
2414
  }
2416
2415
 
2417
2416
  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);
2417
+ try {
2418
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
2419
+ bitmap.compress(Bitmap.CompressFormat.JPEG, 100, outputStream);
2420
+ return Base64.encodeToString(outputStream.toByteArray(), Base64.NO_WRAP);
2421
+ } catch (Exception e) {
2422
+ e.printStackTrace();
2423
+ }
2424
+ return "";
2421
2425
  }
2422
2426
  }