Skip to content
Permalink
Browse files
(Android) Fix NullPointerException error on some Android phones (#429)
  • Loading branch information
hazems authored and janpio committed May 5, 2019
1 parent fae190e commit 295e928784e2a9785982fbf15b05215a317774df
Showing 1 changed file with 10 additions and 10 deletions.
@@ -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);

@@ -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);
@@ -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);
@@ -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 {
@@ -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;
@@ -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;
}
}

@@ -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");
}

0 comments on commit 295e928

Please sign in to comment.