删除图像的副本SD卡 [英] Delete copy of an image in sdcard

查看:87
本文介绍了删除图像的副本SD卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友你好我使用下面的code在我的我的项目。

Hello friends I am using the following code in my my project.

权限:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.CAMERA"/>

XML文件:

XML FILE:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <TextView android:layout_width="wrap_content"
        android:layout_height="wrap_content" android:text="Camera Test" />
    <ImageView android:id="@+id/camera_image"
        android:layout_width="wrap_content" android:layout_height="wrap_content" />
</LinearLayout>

code(Java文件):

Code(Java File):

public class ImageInfo extends Activity {
        private static final int CAMERA_PIC_REQUEST = 1111;
    private ImageView mImage;

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        mImage = (ImageView) findViewById(R.id.camera_image);
        //1
        Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(intent, CAMERA_PIC_REQUEST);
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if(resultCode != RESULT_CANCELED)   {
            if(requestCode == CAMERA_PIC_REQUEST){
                //2
                System.out.println("Request"+requestCode+"result"+resultCode);
                Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
                //  mImage.setImageBitmap(thumbnail);
                //3
                ByteArrayOutputStream bytes = new ByteArrayOutputStream();
                thumbnail.compress(Bitmap.CompressFormat.JPEG, 100, bytes);
                //4
                File file = new File(Environment.getExternalStorageDirectory()+"/saved_images/image.jpeg");
                try {
                    file.createNewFile();
                    FileOutputStream fo = new FileOutputStream(file);
                    //5
                    fo.write(bytes.toByteArray());
                    fo.close();
                    Intent intent=new Intent( this,Info.class);
                    startActivity(intent);
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

            }
        }
    }
}

我能够成功操作相机和拍摄图像的图像布坦额外副本在DCIM目录(deafult目录)的Andr​​oid由name_date.jpg正在形成 请删除所有这些文件帮助。 感谢和放大器;关于.....

I am successfully able to operate the camera and take images butan extra copy of image is being created in the DCIM directory (deafult directory) of android by name_date.jpg Please help in deleting all these files. Thanks & regards.....

推荐答案

这是您的DCIM文件夹删除文件的问题的完整的解决方案。

This is the complete solution of your problem of deleting the file from dcim folder.

just copy and paste this method. And call it whenever necessary.
private void deleteLatest() {
        // TODO Auto-generated method stub
        File f = new File(Environment.getExternalStorageDirectory() + "/DCIM/Camera" );

        //Log.i("Log", "file name in delete folder :  "+f.toString());
        File [] files = f.listFiles();

        //Log.i("Log", "List of files is: " +files.toString());
        Arrays.sort( files, new Comparator<Object>()
                {
            public int compare(Object o1, Object o2) {

                if (((File)o1).lastModified() > ((File)o2).lastModified()) {
                    //         Log.i("Log", "Going -1");
                    return -1;
                } else if (((File)o1).lastModified() < ((File)o2).lastModified()) {
                    //     Log.i("Log", "Going +1");
                    return 1;
                } else {
                    //     Log.i("Log", "Going 0");
                    return 0;
                }
            }

                });

        //Log.i("Log", "Count of the FILES AFTER DELETING ::"+files[0].length());
        files[0].delete();

    }

这篇关于删除图像的副本SD卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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