I want to delete a file in SD card. But before deleting I want to check whether the particular file has write permissions to allow file deletion. (Because Android restricts write access to apps in SD card from Android 4.4+)
File filePath = new File(sdcardImagepath); //Check file write permissions if(filePath.canWrite()) { //canWrite always returns true for sd card files in Android 5.0 // Delete file if(!file.delete()) { //file.delete() is always false for sd card files //Show Deletion error } } else { // Show ACTION_OPEN_DOCUMENT_TREE intent to get permission } In Java File.canWrite() returns false when there are no write permissions. But in android specifically in Android 5.0(I faced problem in this) canWrite() returns true even though there are no write permissions for sd card storage. But this snippet works fine in Android 6.0. canWrite() returns false when there is no write permission. I have referred to the following link regarding this issue. https://code.google.com/p/android/issues/detail?id=66369 But I can neither understand the cause of the issue nor the solution. Please suggest me the right way to test the write permissions of a particular file or folder in SD card in Android 5.0? Or is there any workaround for this issue other than creating a temporary file and deleting it? -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to android-developers+unsubscr...@googlegroups.com. To post to this group, send email to android-developers@googlegroups.com. Visit this group at https://groups.google.com/group/android-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/android-developers/d55504b7-cfb1-4b3a-845d-52400c080f4d%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.