title: How do I delete files programmatically on Android?
body: <p>I'm on 4.4.2, trying to delete a file (image) via uri. Here's my code:</p>
  
  <pre><code>File file = new File(uri.getPath());
  boolean deleted = file.delete();
  if(!deleted){
        boolean deleted2 = file.getCanonicalFile().delete();
        if(!deleted2){
             boolean deleted3 = getApplicationContext().deleteFile(file.getName());
        }
  }
  </code></pre>
  
  <p>Right now, none of these delete functions is actually deleting the file. I also have this in my AndroidManifest.xml:</p>
  
  <pre><code>&lt;uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /&gt;
  &lt;uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" /&gt;
  </code></pre>