delete a text file from content resolver
delete a text file from content resolver
I want to delete a text file from android through its path i am trying below code but the file is not deleting help me if you can
public static void deleteDocumentFile(String fs , Context c) {
File f = new File(fs);
if (f.delete()) {
Log.d("00000", "delete");
if(f.exists()){
try {
f.getCanonicalFile().delete();
} catch (IOException e) {
e.printStackTrace();
}
if(f.exists()){
c.deleteFile(f.getName());
}
}
}
else{
Log.d("00000", "Not delete");
}
Uri uri = MediaStore.Files.getContentUri("external");
String selectionMimeType = MediaStore.Files.FileColumns.MIME_TYPE + "=?";
ContentResolver contentResolver = c.getContentResolver();
if (contentResolver != null) {
Cursor matchingIndex = contentResolver.query(uri, new String{"_id", "_data"},selectionMimeType, new String{fs}, null);
if(matchingIndex != null && matchingIndex.getCount() > 0) {
matchingIndex.moveToFirst();
while (!matchingIndex.isAfterLast()) {
c.getContentResolver().delete(ContentUris.withAppendedId(uri, (long) matchingIndex.getInt(matchingIndex.getColumnIndex("_id"))), null, null);
matchingIndex.moveToNext();
}
matchingIndex.close();
}
}
}
i have tried all possible methods here on stack but not able to do the job please help me
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.