Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Android) Fix NullPointerException error on some Android phones #429

Merged
merged 1 commit into from
May 5, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -389,7 +389,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 @@ -689,7 +689,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 @@ -705,7 +705,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 @@ -912,14 +912,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 @@ -1245,9 +1245,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 @@ -1299,7 +1299,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