I have an app with two main buttons. One open a gallery with every photo on the device and the other one pops up the camera. Both are working fine but here is the thing: When I take a picture with the camera button it doesn't show on the gallery! Not even if I close the app and open it again (forcing the code for the gallery to run again). The only way I can get the picture to show up is to connect the device to my computer via usb and then disconnect (I think forcing a media search, update, something like that.)
Here is the code for the camera intent:
if (getApplicationContext().getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)){
Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
File photo = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), "IMG_" + timeStamp + ".jpg");
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(photo));
imageUri = Uri.fromFile(photo);
startActivityForResult(intent, 1);
} else {
Toast.makeText(getApplicationContext(), "Seu dispositivo Android não possui uma câmera funcional.", Toast.LENGTH_LONG).show();
}
Here is the code for the gallery:
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media._ID;
Cursor imagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,null, orderBy);
int image_column_index = imagecursor.getColumnIndex(MediaStore.Images.Media._ID);
int dataColumnIndex = imagecursor.getColumnIndex(MediaStore.Images.Media.DATA);
this.count = imagecursor.getCount();
this.thumbnails = new Bitmap[this.count];
this.arrPath = new String[this.count];
this.thumbnailsselection = new boolean[this.count];
for (int i = 0; i < this.count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
thumbnails[i] = MediaStore.Images.Thumbnails.getThumbnail(
getApplicationContext().getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null);
arrPath[i]= imagecursor.getString(dataColumnIndex);
PS: I know that managedQuery is deprecated, but it is the only way I know how to do... Thanks!