Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If someone is looking for a simpler work around to this problem, here is how I solved the issue.</p> <p>I have a capture button and when it is pressed the intent is sent, what I added is that I also go and get the last id from image mediastore and store it:</p> <pre><code>/** * Gets the last image id from the media store * @return */ private int getLastImageId(){ final String[] imageColumns = { MediaStore.Images.Media._ID }; final String imageOrderBy = MediaStore.Images.Media._ID+" DESC"; final String imageWhere = null; final String[] imageArguments = null; Cursor imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere, imageArguments, imageOrderBy); if(imageCursor.moveToFirst()){ int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID)); imageCursor.close(); return id; }else{ return 0; } } </code></pre> <p>Then when the activity returns I run this code to checks for the last image id before capture, then queries for images after capture have an id larger then recorded and <em>if it is more then one deletes the record located at the location I specified</em> for the camera to save in.</p> <pre><code>/* * Checking for duplicate images * This is necessary because some camera implementation not only save where you want them to save but also in their default location. */ final String[] imageColumns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media.DATE_TAKEN, MediaStore.Images.Media.SIZE, MediaStore.Images.Media._ID }; final String imageOrderBy = MediaStore.Images.Media._ID+" DESC"; final String imageWhere = MediaStore.Images.Media._ID+"&gt;?"; final String[] imageArguments = { Integer.toString(MyActivity.this.captureLastId) }; Cursor imageCursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere, imageArguments, imageOrderBy); if(imageCursor.getCount()&gt;1){ while(imageCursor.moveToNext()){ int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID)); String path = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA)); Long takenTimeStamp = imageCursor.getLong(imageCursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN)); Long size = imageCursor.getLong(imageCursor.getColumnIndex(MediaStore.Images.Media.SIZE)); if(path.contentEquals(MyActivity.this.capturePath)){ // Remove it ContentResolver cr = getContentResolver(); cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, MediaStore.Images.Media._ID + "=?", new String[]{ Long.toString(id) } ); break; } } } imageCursor.close(); </code></pre> <p>For me this was a much simpler solution, and I tested on my HTC which was having this issue.</p> <p><strong>Another side note</strong>, I originally used *DATE_TAKEN* not *_ID* as the parameter but there seems to be some bug that on the emulator some of the images being captured through the intent had their millsecond *DATE_TAKEN* times multiplied by a 1000 so I switched to *_ID* which seems to be much more robust.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload