I have a requirement to delete screenshot image file after a certain time using background service in my app and it was working fine using the above method
private void deleteTheFile(String path) {
File fdelete = new File(path);
if (fdelete.exists()) {
if (fdelete.delete()) {
getApplicationContext().sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, Uri.fromFile(new File(path))));
Log.i(TAG, "deleteTheFile: file deleted");
} else {
Log.i(TAG, "deleteTheFile: file not dellleeettteeeddd");
}
}
But as everyone knows about the changes which came with android R (11) So I tried to update my app with
MANAGE_EXTERNAL_STORAGE permission
But Google rejected my update saying
Issue: Need to use Media Store API
You have requested access to All Files Access permission but it appears that your app's core feature requires access to only Media Files. With the MediaStore API, apps can contribute and access media that's available on an external storage volume without the need for the access all files permission.
Please update your app so that the feature uses Media Store APIs and remove All Files Access (MANAGE_EXTERNAL_STORAGE) permission.
But I have never worked with media store API before and I don't know can it delete an image file with it, because deleting a file comes under writeable section