Stop saving photos using Android native camera

后端 未结 5 1840
既然无缘
既然无缘 2020-11-29 03:27

I am using native Android camera and save file to my application data folder (/mnt/sdcard/Android/data/com.company.app/files/Pictures/). At the same time anther copy of phot

5条回答
  •  温柔的废话
    2020-11-29 04:10

    I am encountering a similar problem with the Moto Z Force (7.1.1). I have the MediaStore.EXTRA_OUTPUT defined on the intent, but a duplicate file is still created in the camera directory.

    I need to test on other devices, but here's an approach I took regarding this issue. Rather than trying to find the specific camera directory, I'm using the MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME location.

    Here's my code snippet:

    private void removeCameraDuplicate() {
        String[] proj = {
            MediaStore.Images.ImageColumns.DATA,
            MediaStore.Images.ImageColumns._ID };
    
        String selection = MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME + " = ? ";
        String[] selectionArgs = new String[] { "Camera" };
    
        Cursor cursor = mActivity.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, proj, selection, selectionArgs, MediaStore.Images.ImageColumns.DATE_TAKEN + " desc");
    
        if (cursor != null) {
            int idxPath = cursor.getColumnIndex(MediaStore.Images.ImageColumns.DATA);
    
            if (cursor.getCount() > 0 && idxPath > -1 && cursor.moveToFirst()) {
                File original = new File(mMediaPath);
                File cameraDupe = new File(cursor.getString(idxPath));
                if (original.exists() && cameraDupe.exists()) {
                    LogUtils.LOGE("***> camera", "original " + original.length());
                    LogUtils.LOGE("***> camera", "original " + original.lastModified());
    
                    LogUtils.LOGE("***> camera", "duplicate " + cameraDupe.length());
                    LogUtils.LOGE("***> camera", "duplicate " + cameraDupe.lastModified());
    
                    if (original.length() == cameraDupe.length() && original.lastModified() == cameraDupe.lastModified()) {
                        if (cameraDupe.delete()) {
                            LogUtils.LOGE("***> camera", "duplicate deleted");
                        }
                    }
                }
            }
            cursor.close();
        }
    }
    

提交回复
热议问题