Skip to content

Commit

Permalink
(Android) Fix NullPointerException error on some Android phones (#429)
Browse files Browse the repository at this point in the history
  • Loading branch information
hazems authored and janpio committed May 5, 2019
1 parent fae190e commit 295e928
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/android/CameraLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public void takePicture(int returnType, int encodingType)
this.imageUri = new CordovaUri(FileProvider.getUriForFile(cordova.getActivity(),
applicationId + ".provider",
photo));
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, imageUri.getCorrectUri());
intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri.getCorrectUri());
//We can write to this URI, this will hopefully allow us to write files to get to the next step
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);

Expand Down Expand Up @@ -387,7 +387,7 @@ public void getImage(int srcType, int returnType, int encodingType) {
}
File photo = createCaptureFile(JPEG);
croppedUri = Uri.fromFile(photo);
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri);
intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedUri);
} else {
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
Expand Down Expand Up @@ -687,7 +687,7 @@ private void processResultFromGallery(int destType, Intent intent) {
int rotate = 0;

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

String uriString = uri.toString();
String mimeType = FileHelper.getMimeType(uriString, this.cordova);
Expand All @@ -703,7 +703,7 @@ private void processResultFromGallery(int destType, Intent intent) {
// rotating, nor compressing needs to be done
if (this.targetHeight == -1 && this.targetWidth == -1 &&
(destType == FILE_URI || destType == NATIVE_URI) && !this.correctOrientation &&
mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
mimeType != null && mimeType.equalsIgnoreCase(getMimetypeForFormat(encodingType)))
{
this.callbackContext.success(uriString);
} else {
Expand Down Expand Up @@ -910,14 +910,14 @@ private void writeUncompressedImage(Uri src, Uri dest) throws FileNotFoundExcept
*/
private Uri getUriFromMediaStore() {
ContentValues values = new ContentValues();
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, JPEG_MIME_TYPE);
values.put(MediaStore.Images.Media.MIME_TYPE, JPEG_MIME_TYPE);
Uri uri;
try {
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
uri = this.cordova.getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} catch (RuntimeException e) {
LOG.d(LOG_TAG, "Can't write to external media storage.");
try {
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
uri = this.cordova.getActivity().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
} catch (RuntimeException ex) {
LOG.d(LOG_TAG, "Can't write to internal media storage.");
return null;
Expand Down Expand Up @@ -1243,9 +1243,9 @@ private void checkForDuplicateImage(int type) {
*/
private Uri whichContentStore() {
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
return android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
return MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
} else {
return android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI;
return MediaStore.Images.Media.INTERNAL_CONTENT_URI;
}
}

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

Expand Down

0 comments on commit 295e928

Please sign in to comment.