My app is able to open and process certain files. So you can tap on such a file for example in a file manager, and my app will be offered to open it. The intent filter in the manifest file is set up something like this.
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:mimeType="text/plain" />
</intent-filter>
Reading and processing the file like this works fine:
Context.getContentResolver().openInputStream(getIntent().getData());
The issue is, that I want to delete the file after processing it. (If the user checks a checkbox for it) Users typically don't need the file anymore after opening it with my app.
Currently I am only able to do it if the file is provided to me as a file uri (starting with file://). In this case this code works fine:
new File(contentUri.getPath()).delete();
But I don't know how to delete the file if it is provided as a content uri. (starting with content://)
For example this returns null, and does nothing:
Context.getContentResolver().delete(getIntent().getData(), null, null);