I am trying to delete an audio file in my app using the below code but for some reason it doesn't work out . file.delete() returns false even though the path is correct. Please help.I have also added WRITE and READ EXTERNAL STORAGE permission in Manifest. My phone is not connected to PC during testing.
File file = new File(song.getPathId());
files.add(file);
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
MainActivity.this);
// set title
alertDialogBuilder.setTitle("Delete");
// set dialog message
alertDialogBuilder
.setMessage("Confirm delete")
.setCancelable(false)
.setPositiveButton("Yes",new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog,int id) {
for(int i=0;i<files.size();i++)
{
fileDeleted=files.get(i).delete();//returns false but path is correct
}