Reputation: 1020
Im trying to implement a small file Explore within my app in order to give to the user the ability to select new path (to store X) instead of the default path, also i want the user to be able to create and delete file.
So far my code is working however there is something really weird, im able to delete only file that i created myself within the app.
I have read a lot of file deletion tutorial example, here and there and i last time i check i have both read/write permission in my app manifest but still i cant delete files others than the one i created. here is the latest deletion code:
File file = new File(customAdapter.getItem(position).getFile().getAbsolutePath());
boolean isDeleted = file.delete();
if(!isDeleted){
Log.e("File manager: ",customAdapter.getItem(position).getFile().getName()+" deletion Fail");
} else {
fileHolderList.remove(position);
customAdapter.notifyDataSetChanged();
}
I have also read somewhere that for some security purposes android allow you to delete only file that your package created, ok but what about those file Explorer app in the play store which allow you a full control of your sd card or internal storage files. How do they did that? So that mean there is a way.
Please anyone can help with that?
Edit: i mean by file here Folder.
Upvotes: 0
Views: 379
Reputation: 5012
You can only modify files located on SDCard type, public storage. Whether real or emulated. Are you trying to modify files from the Internal storage? You need root permissions for changing anything outside your app's default data directories on the Internal Storage.
Since I now know that you are attempting to delete directories I assume that you are trying to delete directories that contain files. You should recursively delete the directory's contents before deleting the directory itself. See this question for how to go about that: https://stackoverflow.com/a/4026761/1590950
Upvotes: 3