在Android的替代文件中删除 [英] Override file delete in android

查看:135
本文介绍了在Android的替代文件中删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有可能重写File.delete()函数?每当我(而不是我的应用程序中使用)中删除从其他应用程序的SD卡的任何文件,我需要这样的文件通知,将是删除。样本code段我想是,

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();
     }
}  

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

我实现了上面的 FileObsever 服务类两种说法。 现在,我删除了其他应用程序tmp.txt文件,但我没有得到任何通知。 我怎样才能从其他应用程序的通知?是否有可能或不?

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 ?

在此先感谢

推荐答案

没有,这是不可能的。这不仅会引起问题与其他应用程序也与Android操作系统。

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

随着FileObserver你只能看到发生在一个文件中。你不能影响它。 总之:如果你只是想知道发生了什么事/mnt/sdcard/tmp.txt然后用FileObserver,但你不能prevent删除

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.

这篇关于在Android的替代文件中删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆