Override file delete in android

无人久伴 提交于 2020-01-04 09:17:51

问题


Is it possible to override File.delete() function? Whenever i delete any file from sdcard from other apps (not using by my application) i need a notification like this file is going to be delete. A sample code snippet i tried is,

public class ExtendFile extends File
{
    public ExtendFile(File dir, String name) 
    {
         super(dir, name);
         // TODO Auto-generated constructor stub
    }

    @Override
    public boolean delete() 
    {    
        System.out.println("to be deleted");
        return super.delete();
     }
}  

and

File file = new File("/mnt/sdcard/tmp.txt");
ExtendFile f = new ExtendFile(file, tempPath);

i implemented above two statements in a service class in FileObsever. Now i deleted tmp.txt file from other app, but i didn't get any notification. How can i get the notifications from other apps ? Is it possible or not ?

Thanks in advance


回答1:


No, this is not possible. Not only will this cause problems with other applications but also with the Android OS.

With the FileObserver you can only see what has happened to a file. You cannot influence it. To conclude: If you only want to know what has happened to "/mnt/sdcard/tmp.txt" then use a FileObserver, but you cannot prevent deletion.



来源:https://stackoverflow.com/questions/18888231/override-file-delete-in-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!