如何停止 MediaStore.ACTION_IMAGE_CAPTURE 复制图片 [英] How can I stop MediaStore.ACTION_IMAGE_CAPTURE duplicating pictures

查看:35
本文介绍了如何停止 MediaStore.ACTION_IMAGE_CAPTURE 复制图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用以下代码拍照:

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.

感谢您的帮助!

推荐答案

我找到了答案.

以下功能删除保存到媒体存储的最后一张照片.

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

请在 onActivityResult 中调用上述函数.

Please call above function within onActivityResult.

这篇关于如何停止 MediaStore.ACTION_IMAGE_CAPTURE 复制图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆