Skip to content

Commit

Permalink
Merge pull request #4148 from pingwang2011/timob-13159
Browse files Browse the repository at this point in the history
timob-13159: Android: Images are blank/ have an empty entry when saved to the photo gallery
  • Loading branch information
ayeung committed Apr 18, 2013
2 parents 881f61e + 5facfb0 commit d1c9b60
Showing 1 changed file with 17 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -473,24 +473,19 @@ public void onResult(Activity activity, int requestCode, int resultCode, Intent

String localImageUrl = dataPath;

// We need to move the image from dataPath to imageUrl
URL url;
try {
if (!saveToPhotoGallery) {
// We need to move the image from dataPath to the temp file which will be deleted
// when the app exits.
url = new URL(imageUrl);
moveImage(dataPath, url.getPath());

// Update Content
ContentValues values = new ContentValues();
values.put(Images.ImageColumns.BUCKET_ID, imageFile.getPath().toLowerCase().hashCode());
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, imageFile.getName());
values.put("_data", imageFile.getAbsolutePath());

// Delete the saved the image entry from the gallery DB.
if (data.getData() != null && isDataValid) {
activity.getContentResolver().update(data.getData(), values, null, null);
activity.getContentResolver().delete(data.getData(), null, null);
} else {
activity.getContentResolver().update(Images.Media.EXTERNAL_CONTENT_URI, values,
"datetaken = ?", new String[] { dateTaken });
activity.getContentResolver().delete(Images.Media.EXTERNAL_CONTENT_URI, "datetaken = ?", new String[] { dateTaken });
}

localImageUrl = imageUrl; // make sure it's a good URL before setting it to pass back.
Expand Down Expand Up @@ -550,32 +545,29 @@ private void processImage(Activity activity)
{
String localUrl = imageUrl;
String localPath = imageFile.getAbsolutePath();
ContentValues values = new ContentValues(7);

values.put(Images.Media.TITLE, imageFile.getName());
values.put(Images.Media.DISPLAY_NAME, imageFile.getName());
values.put(Images.Media.DATE_TAKEN, new Date().getTime());
values.put(Images.Media.MIME_TYPE, "image/jpeg");
if (saveToPhotoGallery) {
ContentValues values = new ContentValues(7);
values.put(Images.Media.TITLE, imageFile.getName());
values.put(Images.Media.DISPLAY_NAME, imageFile.getName());
values.put(Images.Media.DATE_TAKEN, new Date().getTime());
values.put(Images.Media.MIME_TYPE, "image/jpeg");

File rootsd = Environment.getExternalStorageDirectory();
localPath = rootsd.getAbsolutePath() + "/dcim/Camera/" + imageFile.getName();
values.put(Images.ImageColumns.BUCKET_ID, localPath.toLowerCase().hashCode());
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, "Camera");
moveImage(imageFile.getAbsolutePath(), localPath);
localUrl = "file://" + localPath;

} else {
values.put(Images.ImageColumns.BUCKET_ID, imageFile.getPath().toLowerCase().hashCode());
values.put(Images.ImageColumns.BUCKET_DISPLAY_NAME, imageFile.getName());
}
values.put("_data", localPath);

activity.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);
values.put("_data", localPath);

// puts newly captured photo into the gallery
MediaScannerClient mediaScanner = new MediaScannerClient(activity, new String[] { localUrl }, null, null);
mediaScanner.scan();
activity.getContentResolver().insert(Images.Media.EXTERNAL_CONTENT_URI, values);

// puts newly captured photo into the gallery
MediaScannerClient mediaScanner = new MediaScannerClient(activity, new String[] { localUrl }, null, null);
mediaScanner.scan();
}
invokeSuccessCallback(activity, localPath);
}

Expand Down

0 comments on commit d1c9b60

Please sign in to comment.