0

I am not able to delete files from the device. I am getting the file right but when calling file.exists() it returns false. This is how I create the file.

File file = new File(uri.getPath()); 

When printing URI it shows - /external_files/Android/data/com.akshit.akshitsfdc.allpuranasinhindi/files/puran_collection/filename.pdf

 if(uri == null){
        Log.d("FileUtils", "deleteFileFromUri: null uri");
        return false;
    }
    File file = new File(uri.getPath());
    Log.d("FileUtils", "deleteFileFromUri: file : "+file+" : "+file.exists());

    if(file != null){
        try{
           return file.delete();
        }catch (Exception e){
            e.printStackTrace();
            return false;
        }

    }
    Log.d("FileUtils", "deleteFileFromUri: file does not exists : "+uri.getPath());
mad_lad
  • 654
  • 3
  • 8
  • 20

0 Answers0