Android 意图操作\u图像\u捕获-如何删除重复的缩略图?

Android 意图操作\u图像\u捕获-如何删除重复的缩略图?,android,android-intent,android-camera-intent,Android,Android Intent,Android Camera Intent,在使用指定位置的intent ACTION_IMAGE_CAPTURE在某些设备上保存照片后,我的测试设备是Sony Ericsson Mt11i和android 2.3。默认的相机应用程序正在相机照片文件夹中保存重复图像 因此,我的应用程序会检查照片是否重复并将其删除。但是相机应用程序也保存了拍摄照片的缩略图,所以我也在删除它,但是即使删除了这个缩略图,仍然有关于这个缩略图的信息,并且在设备的gallery应用程序中,图像仍然与默认图像一起出现。如果我查看这张图片的详细信息,仍然有这张照片的日

在使用指定位置的intent ACTION_IMAGE_CAPTURE在某些设备上保存照片后,我的测试设备是Sony Ericsson Mt11i和android 2.3。默认的相机应用程序正在相机照片文件夹中保存重复图像

因此,我的应用程序会检查照片是否重复并将其删除。但是相机应用程序也保存了拍摄照片的缩略图,所以我也在删除它,但是即使删除了这个缩略图,仍然有关于这个缩略图的信息,并且在设备的gallery应用程序中,图像仍然与默认图像一起出现。如果我查看这张图片的详细信息,仍然有这张照片的日期、位置信息。以下是我处理重复照片的方法:

public static void handleTakenPicture(Context context, int lastId, File tempFile) {
    /*
     * Checking for duplicate images
     * This is necessary because some camera implementation not only save where you want them to save but also in their default location.
     */
    if (lastId == 0)
        return;
    final String[] projection = {MediaStore.Images.ImageColumns.DATA, MediaStore.Images.ImageColumns.DATE_TAKEN,
            MediaStore.Images.ImageColumns.SIZE, MediaStore.Images.ImageColumns._ID};
    final String imageOrderBy = MediaStore.Images.Media._ID + " DESC";
    final String imageWhere = MediaStore.Images.Media._ID + ">?";
    final String[] imageArguments = {Integer.toString(lastId)};
    Cursor imageCursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, projection, imageWhere, imageArguments,
            imageOrderBy);
   // List<File> cameraTakenMediaFiles = new ArrayList<File>();
    File gFile = null;
    if (imageCursor.getCount() > 0) {
       // while( imageCursor.moveToNext() ) {
        imageCursor.moveToFirst();
            // int id =
            // imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
            String path = imageCursor.getString(imageCursor.getColumnIndex(MediaStore.Images.Media.DATA));
            gFile = new File(path);
            // Long takenTimeStamp =
            // imageCursor.getLong(imageCursor.getColumnIndex(MediaStore.Images.Media.DATE_TAKEN));
            // Long size =
            // imageCursor.getLong(imageCursor.getColumnIndex(MediaStore.Images.Media.SIZE));
           // cameraTakenMediaFiles.add(new File(path));
        //}
    }

    imageCursor.close();


    //File imageFile = new File(imageFilePath);


    if (!tempFile.exists() && gFile != null) {
        // was not saved where I wanted, but the camera saved one in the media folder
        // try to copy over the one saved by the camera and then delete
        try {
            Prefsy.copyFile(gFile, tempFile);
            gFile.delete();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    if(gFile != null)
        {
        gFile.delete();
        try { // DELETING THUMBNAIL
            Cursor th = context.getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, new String[] {MediaStore.Images.ImageColumns.DATA},
                    MediaStore.Images.Thumbnails.IMAGE_ID + " = ?", new String[] {"" + lastId}, MediaStore.Images.Thumbnails._ID + " DESC");

            L(th.getCount()+"");

            if (th.getCount() > 0)
            {
                th.moveToFirst();
                L(th.getString(0));
                L(new File(th.getString(0)).delete()+"");
                L(context.getContentResolver().delete(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                        MediaStore.Images.Thumbnails.IMAGE_ID + " = ?", new String[] {"" + lastId})+"");
            }
            th.close();
        } catch (Exception e) {
        }

        }
    /*for( File cameraTakenFile : cameraTakenMediaFiles ) {
        // delete the one duplicated
        cameraTakenFile.delete();
    }*/
}

public static int getLastImageId(Context context){
    final String[] imageColumns = { MediaStore.Images.Media._ID };
    final String imageOrderBy = MediaStore.Images.Media._ID+" DESC";
    final String imageWhere = null;
    final String[] imageArguments = null;
    Cursor imageCursor = context.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, imageColumns, imageWhere, imageArguments, imageOrderBy);
    if(imageCursor.moveToFirst()){
        int id = imageCursor.getInt(imageCursor.getColumnIndex(MediaStore.Images.Media._ID));
        imageCursor.close();
        return id;
    }else{
        return 0;
    }
}
L是对数法