How can I stop MediaStore.ACTION_IMAGE_CAPTURE duplicating pictures

后端 未结 1 434
谎友^
谎友^ 2020-12-17 06:33

I am using the following code to take a picture:

private static final int TAKE_PHOTO_CODE = 1;

final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPT         


        
相关标签:
1条回答
  • 2020-12-17 07:15

    I have found a answer.

    Following function delete the last photo saved to media storage.

    public void deleteLastCapturedImage() {
        String[] projection = { 
                MediaStore.Images.ImageColumns.SIZE,
                MediaStore.Images.ImageColumns.DISPLAY_NAME,
                MediaStore.Images.ImageColumns.DATA, 
                BaseColumns._ID
        };
    
        Cursor c = null;
        Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
    
        try {
            if (u != null) {
                c = managedQuery(u, projection, null, null, null);
            }
            if ((c != null) && (c.moveToLast())) {
    
                ContentResolver cr = getContentResolver();
                int i = cr.delete(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, BaseColumns._ID + "=" + c.getString(c.getColumnIndex(BaseColumns._ID)), null);
    
                Log.v(LOG_TAG, "Number of column deleted : " + i);
    
            }
        } finally {
            if (c != null) {
                c.close();
            }
        }
    }
    

    Please call above function within onActivityResult.

    0 讨论(0)
提交回复
热议问题