I'm having a trouble with my Android application developed with Eclipse.
The problem is that when I capture a new image using the folowing instructions:
intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, Uri.fromFile(file)); startActivityForResult(intent, TAKE_IMAGE); The device stores the file correctly in the right destination(extSdCard), but the following code which is supposed to reload the directory content doesn't find the new files until the device is rebooted.
images.clear();
final String[] columns = { MediaStore.Images.Thumbnails._ID };
final String orderBy = MediaStore.Images.Media._ID;
String condition = MediaStore.Images.Media.DATA + " like '%/"+
Singleton.getCurrentPatient().getNrdo()+"/%'";
Cursor imagecursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns,
condition, null, orderBy);
if(imagecursor != null){
int image_column_index = imagecursor
.getColumnIndex(MediaStore.Images.Media._ID);
int count = imagecursor.getCount();
for (int i = 0; i < count; i++) {
imagecursor.moveToPosition(i);
int id = imagecursor.getInt(image_column_index);
ImageItem imageItem = new ImageItem();
imageItem.id = id;
lastId = id;
imageItem.img = MediaStore.Images.Thumbnails.getThumbnail(
getApplicationContext().getContentResolver(), id,
MediaStore.Images.Thumbnails.MICRO_KIND, null);
images.add(imageItem);
}
imagecursor.close();
}
notifyDataSetChanged();
}
Unfortunatrly, i tried many solutions and nothing works
I first used this code
mScanner = new MediaScannerConnection(
AndroidCustomGalleryActivity.this,new MediaScannerConnection.MediaScannerConnectionClient() {
public void onMediaScannerConnected() {
mScanner.scanFile(imageUri.getPath(), null /* mimeType */);
}
public void onScanCompleted(String path, Uri uri) {
if (path.equals(imageUri.getPath())) {
mScanner.disconnect();
AndroidCustomGalleryActivity.this
.runOnUiThread(new Runnable() {
public void run() {
updateUI();
}
});
}
}
});
mScanner.connect();
The imageUri contains the correct path on the onMediaScannerConnected method but the onScanCompleted is never called
I then tried thoseinstructions after the photo is captured
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, imageUri));
updateUI();
Once again, the updateUI method don't detect the new file.
Could you help me please ?