简体   繁体   中英

Delete picture taken from camera

I'm trying to delete the picture just taken by the app because I already saved it to my tmp folder for later use and I don't want the picture to show up in the gallery. Problem is that I can't figure out how to do it, I tried a bunch of things and now I'm stuck. This is my latest code (the data in the onActivityResult is null and I don't know why):

protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (requestCode == TAKE_PIC && resultCode == RESULT_OK) {
        Uri path = data.getData();
        new File(path.getPath()).delete();
        Toast.makeText(this, "Picture taken!", Toast.LENGTH_LONG).show();
    }
}

public void onButtonClick(View view) {
    CheckBox ckBox = (CheckBox) findViewById(R.id.cmark_picture);

    if (ckBox.isChecked())
        takePicture(view);
}

private void takePicture(View view) {
    tmpImg = new File(TMPDIR, "tmp.png");
    Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(tmpImg));
    startActivityForResult(intent, TAKE_PIC);
}

Use below code for deleting the captured image after completion of your purpose

File casted_image = new File("path of image");
                if (casted_image.exists()) {
                casted_image.delete();
                }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM