Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
575 views
in Technique[技术] by (71.8m points)

android - How can I stop MediaStore.ACTION_IMAGE_CAPTURE duplicating pictures

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_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tFile));
startActivityForResult(intent, TAKE_PHOTO_CODE);

This code works fine however I am getting a copy of every picture I take automatically appearing in the "Camera Shots" gallery as well as where I want the picture to go.

How do I stop it automatically copying my picture?

The file name is not even the same as the one I specified so it is not like I can delete it easily.

Thanks for any help!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...