0

File is not getting deleted in Android, I have checked all premissions, and I tried all the solutions available in the internet but nothing helps. Your help will be highly assist me. Thanks in advance.

I used the below permissions

<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
<uses-permission android:name="android.permission.MANAGE_EXTERNAL_STORAGE" />

And this is the code I used

File dir = Environment.getExternalStorageDirectory();
String path = dir.getAbsolutePath() + "/Recordings/Call/" + filename;
File fdelete = new File(path);
    if (fdelete.exists()) {
      if (fdelete.delete()) {
        System.out.println("file Deleted :" + path);
      } else {                                              
        System.out.println("file not Deleted :" + path);
      }
 }

And the err log is

W/soft.my_app_name: Got a deoptimization request on un-deoptimizable method void libcore.io.Linux.remove(java.lang.String)

enter image description here

Error log is

enter image description here

Anand
  • 4,355
  • 2
  • 35
  • 45
  • I can't see any error. I see only a warning – Jens Jan 03 '23 at 08:08
  • You really should use [`Files.delete(Path)`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#delete(java.nio.file.Path)) or [`Files.deleteIfExists(Path)`](https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/nio/file/Files.html#deleteIfExists(java.nio.file.Path)) ... – Seelenvirtuose Jan 03 '23 at 08:34
  • which Android API level are you testing on ? – Abraham Mathew Jan 03 '23 at 09:33
  • I tested all these api versions 30,31,32 – Anand Jan 04 '23 at 05:34

0 Answers0