如何停止 MediaStore.ACTION_IMAGE_CAPTURE 复制图片

发布于 2024-12-05 14:24:09 字数 412 浏览 0 评论 0原文

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

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

该代码工作正常,但是我得到了我自动拍摄的每张照片的副本,这些照片出现在“相机镜头”画廊以及我想要照片去的地方。

如何阻止它自动复制我的图片?

该文件名甚至与我指定的文件名不同,因此我无法轻松删除它。

感谢您的帮助!

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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

各自安好 2024-12-12 14:24:09

我找到了答案。

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

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 中调用上述函数。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文