user2281689
user2281689

Reputation: 1

android - hidden file

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();
}

Any idea about that? Must we do a commit to refresh some cache?

Upvotes: 0

Views: 490

Answers (1)

laalto
laalto

Reputation: 152927

You can use MediaScannerConnection to notify the system of new media files. MediaScanner also runs as part of boot sequence so that's why you see the files appearing in MediaStore after a reboot.

Upvotes: 3

Related Questions