I have this code that deletes a specific file under a folder that I've created earlier "pass", what I want is to delete any file a user clicks on, not this particular file "myfile"
public void function1(int id){
Toast.makeText(this, "function 1 called", Toast.LENGTH_SHORT).show();
String fileName = Environment.getExternalStorageDirectory() +"/pass/myfile.pdf";
File myFile = new File(fileName);
if(myFile.exists())
myFile.delete();
I've been trying to pass parameters from another class to this class using, but it doesn't work
file_name = getIntent().getStringExtra("fileName");
String fileName = Environment.getExternalStorageDirectory() +"/pass/"+file_name;
File myFile = new File(fileName);
if(myFile.exists())
myFile.delete();
this class passes the file name
if (position == 0) {
// pass parameters file name & file url
Intent s = new Intent(getApplicationContext(),PDFListActivity.class);
s.putExtra("fileName","myfile.pdf");
startActivity(s);
have you tried
String fileName = Environment.getExternalStorageDirectory().getAbsolutePath() + "/pass/" + file_name;
As getAbsolutePath()
returns the absolute path to the root directory.
Also get log outputs for the Strings you are using to find the file and check if they are same in both instances