Skip to content

Commit c954c24

Browse files
committed
GH-420 (all) DATA_URL is improperly prefixed
1 parent 81b878d commit c954c24

File tree

6 files changed

+33
-332
lines changed

6 files changed

+33
-332
lines changed

appium-tests/helpers/cameraHelper.js

Lines changed: 0 additions & 311 deletions
This file was deleted.

src/android/CameraLauncher.java

Lines changed: 18 additions & 9 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

@@ -389,7 +389,7 @@ public void getImage(int srcType, int returnType, int encodingType) {
389389
}
390390
File photo = createCaptureFile(JPEG);
391391
croppedUri = Uri.fromFile(photo);
392-
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, croppedUri);
392+
intent.putExtra(MediaStore.EXTRA_OUTPUT, croppedUri);
393393
} else {
394394
intent.setAction(Intent.ACTION_GET_CONTENT);
395395
intent.addCategory(Intent.CATEGORY_OPENABLE);
@@ -912,14 +912,14 @@ private void writeUncompressedImage(Uri src, Uri dest) throws FileNotFoundExcept
912912
*/
913913
private Uri getUriFromMediaStore() {
914914
ContentValues values = new ContentValues();
915-
values.put(android.provider.MediaStore.Images.Media.MIME_TYPE, JPEG_MIME_TYPE);
915+
values.put(MediaStore.Images.Media.MIME_TYPE, JPEG_MIME_TYPE);
916916
Uri uri;
917917
try {
918-
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
918+
uri = this.cordova.getActivity().getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
919919
} catch (RuntimeException e) {
920920
LOG.d(LOG_TAG, "Can't write to external media storage.");
921921
try {
922-
uri = this.cordova.getActivity().getContentResolver().insert(android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
922+
uri = this.cordova.getActivity().getContentResolver().insert(MediaStore.Images.Media.INTERNAL_CONTENT_URI, values);
923923
} catch (RuntimeException ex) {
924924
LOG.d(LOG_TAG, "Can't write to internal media storage.");
925925
return null;
@@ -1245,9 +1245,9 @@ private void checkForDuplicateImage(int type) {
12451245
*/
12461246
private Uri whichContentStore() {
12471247
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
1248-
return android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
1248+
return MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
12491249
} else {
1250-
return android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI;
1250+
return MediaStore.Images.Media.INTERNAL_CONTENT_URI;
12511251
}
12521252
}
12531253

@@ -1261,14 +1261,23 @@ public void processPicture(Bitmap bitmap, int encodingType) {
12611261
CompressFormat compressFormat = encodingType == JPEG ?
12621262
CompressFormat.JPEG :
12631263
CompressFormat.PNG;
1264+
String imageMimeType = encodingType == JPEG ?
1265+
JPEG_MIME_TYPE :
1266+
PNG_MIME_TYPE;
12641267

12651268
try {
12661269
if (bitmap.compress(compressFormat, mQuality, jpeg_data)) {
12671270
byte[] code = jpeg_data.toByteArray();
12681271
byte[] output = Base64.encode(code, Base64.NO_WRAP);
12691272
String js_out = new String(output);
1270-
this.callbackContext.success(js_out);
1273+
String base64Prefix = "data:" + imageMimeType + ";base64,";
1274+
String finalJsOut = base64Prefix + js_out;
1275+
1276+
this.callbackContext.success(finalJsOut);
1277+
12711278
js_out = null;
1279+
base64Prefix = null;
1280+
finalJsOut = null;
12721281
output = null;
12731282
code = null;
12741283
}
@@ -1299,7 +1308,7 @@ private void scanForGallery(Uri newImage) {
12991308
public void onMediaScannerConnected() {
13001309
try {
13011310
this.conn.scanFile(this.scanMe.toString(), "image/*");
1302-
} catch (java.lang.IllegalStateException e) {
1311+
} catch (IllegalStateException e) {
13031312
LOG.e(LOG_TAG, "Can't scan file in MediaScanner after taking picture");
13041313
}
13051314

0 commit comments

Comments
 (0)