Skip to content
Closed
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
16 changes: 13 additions & 3 deletions src/camera.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,13 @@ export let takePicture = function (options?): Promise<any> {
let tempPictureUri;

if (saveToGallery) {
picturePath = android.os.Environment.getExternalStoragePublicDirectory(
android.os.Environment.DIRECTORY_DCIM).getAbsolutePath() + "/Camera/" + "NSIMG_" + dateStamp + ".jpg";

// reference the expected public output dir
const outputPath = android.os.Environment.getExternalStoragePublicDirectory(android.os.Environment.DIRECTORY_DCIM).getAbsolutePath() + "/Camera/";
const outputDir = new java.io.File(outputPath);
// and create it, if it doesn't exist (Android won't do it on 28+)
if (!outputDir.exists())
outputDir.mkdir();
picturePath = outputDir.getAbsolutePath() + "/NSIMG_" + dateStamp + ".jpg";
nativeFile = new java.io.File(picturePath);
} else {
picturePath = utils.ad.getApplicationContext().getExternalFilesDir(null).getAbsolutePath() + "/" + "NSIMG_" + dateStamp + ".jpg";
Expand Down Expand Up @@ -111,6 +115,12 @@ export let takePicture = function (options?): Promise<any> {
}
}

// verify that there is a file where we expect one
const picFile = new java.io.File(picturePath);
if (! picFile.exists()) {
return reject('Cannot locate the picture file');
}

let exif = new android.media.ExifInterface(picturePath);
let orientation = exif.getAttributeInt(android.media.ExifInterface.TAG_ORIENTATION,
android.media.ExifInterface.ORIENTATION_NORMAL);
Expand Down