Skip to content

Commit 295e928

Browse files
hazemsjanpio
authored andcommitted
(Android) Fix NullPointerException error on some Android phones (#429)
1 parent fae190e commit 295e928

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/android/CameraLauncher.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,7 @@ public void takePicture(int returnType, int encodingType)
303303
this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
304304
applicationId + ".provider",
305305
photo));
306-
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri.getCorrectUri());
306+
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri.getCorrectUri());
307307
//We can write to this URI, this will hopefully allow us to write files to get to the next step
308308
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
309309

@@ -387,7 +387,7 @@ public void getImage(int srcType, int returnType, int encodingType) {
387387
}
388388
File photo = createCaptureFile(JPEG);
389389
croppedUri = Uri.fromFile(photo);
390-
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri);
390+
intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedUri);
391391
} else {
392392
intent.setAction(Intent.ACTION_GET_CONTENT);
393393
intent.addCategory(Intent.CATEGORY_OPENABLE);
@@ -687,7 +687,7 @@ private void processResultFromGallery(int destType, Intent intent) {
687687
int rotate = 0;
688688

689689
String fileLocation = FileHelper.getRealPath(uri, this.cordova);
690-
LOG.d(LOG_TAG, "File locaton is: " + fileLocation);
690+
LOG.d(LOG_TAG, "File location is: " + fileLocation);
691691

692692
String uriString = uri.toString();
693693
String mimeType = FileHelper.getMimeType(uriString, this.cordova);
@@ -703,7 +703,7 @@ private void processResultFromGallery(int destType, Intent intent) {
703703
// rotating, nor compressing needs to be done
704704
if (this.targetHeight == -1 && this.targetWidth == -1 &&
705705
(destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation &&
706-
mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
706+
mimeType != null && mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
707707
{
708708
this.callbackContext.success(uriString);
709709
} else {
@@ -910,14 +910,14 @@ private void writeUncompressedImage(Uri src, Uri dest) throws FileNotFoundExcept
910910
*/
911911
private Uri getUriFromMediaStore() {
912912
ContentValues values = new ContentValues();
913-
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, JPEG_MIME_TYPE);
913+
values.put(MediaStore.Images.Media.MIME_TYPE, JPEG_MIME_TYPE);
914914
Uri uri;
915915
try {
916-
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
916+
uri = this.cordova.getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
917917
} catch (RuntimeException e) {
918918
LOG.d(LOG_TAG, "Can't write to external media storage.");
919919
try {
920-
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
920+
uri = this.cordova.getActivity().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
921921
} catch (RuntimeException ex) {
922922
LOG.d(LOG_TAG, "Can't write to internal media storage.");
923923
return null;
@@ -1243,9 +1243,9 @@ private void checkForDuplicateImage(int type) {
12431243
*/
12441244
private Uri whichContentStore() {
12451245
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
1246-
return android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
1246+
return MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
12471247
} else {
1248-
return android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI;
1248+
return MediaStore.Images.Media.INTERNAL_CONTENT_URI;
12491249
}
12501250
}
12511251

@@ -1297,7 +1297,7 @@ private void scanForGallery(Uri newImage) {
12971297
public void onMediaScannerConnected() {
12981298
try {
12991299
this.conn.scanFile(this.scanMe.toString(), "image/*");
1300-
} catch (java.lang.IllegalStateException e) {
1300+
} catch (IllegalStateException e) {
13011301
LOG.e(LOG_TAG, "Can't scan file in MediaScanner after taking picture");
13021302
}
13031303

0 commit comments

Comments
 (0)