Im developing an android app which selects an image from the gallery in one activity and displays it in another.But when I try to delete the selected image it doesnt delete.I'm passing its uri between the two activies. Many thanks in Advance!!!!
Here's my Code :
ACTIVITY HOMESCREEN
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == PICK_IMAGE_REQUEST && resultCode == RESULT_OK && data != null && data.getData() != null) {
Uri uri = data.getData();
Intent i = new Intent(this, Imageviewer.class);
i.putExtra("imgpath", uri.toString());
startActivity(i);
}
}
IMAGEVIEWER ACTIVITY :
Uri imageUri;
imageUri = Uri.parse(intent.getStringExtra("imgpath"));
File fdelete = new File(imageUri.toString());
if (fdelete.exists()) {
if (fdelete.delete()) {
System.out.println("file Deleted :" );
} else {
System.out.println("file not Deleted :");
}
}
Try this : (In the second
Activity
)ImageViewerActivity
in your case.Also you can debug your codes line by line to see and check if the
ImgPath
is getting correctly or not!