安卓:FileObserver只监视顶级目录 [英] Android: FileObserver monitors only top directory

查看:511
本文介绍了安卓:FileObserver只监视顶级目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据该文件,

 每个FileObserver实例监控单个文件或目录。如果一个目录被监控,
事件将触发对监控目录中的所有文件和子目录。
 

我的code是这样,

  FileObserver fobsv =新FileObserver(到/ mnt / SD卡/){

    @覆盖
    公共无效的onEvent(INT事件,字符串路径){
        的System.out.println(事件++路径);
    }
    };
    fobsv.startWatching();
 

不过,的onEvent()被触发,只有当一个文件中的的/ mnt / SD卡/ 被改变。如果我创建一个文件中的的/ mnt / SD卡/下载/ ,该方法不被解雇。

有没有用code什么问题?

解决方案
  

根据文档

该文档是不正确,因为被记录在这个问题

  

有没有用code什么问题?

没有,但 FileObserver 不是递归,尽管文档与此相反。

According to the documentation,

"Each FileObserver instance monitors a single file or directory. If a directory is monitored, 
events will be triggered for all files and subdirectories inside the monitored directory."

My code goes like,

    FileObserver fobsv = new FileObserver("/mnt/sdcard/") {

    @Override
    public void onEvent(int event, String path) {
        System.out.println(event+"    "+path);
    }
    };
    fobsv.startWatching();

However, the onEvent() is triggering only when a file is changed in the /mnt/sdcard/. If I create a file in /mnt/sdcard/downloads/, the method is not getting fired.

Is there any problem with the code?

解决方案

According to the documentation

The documentation is incorrect, as is noted in this issue.

Is there any problem with the code?

No, but FileObserver is not recursive, despite the documentation to the contrary.

这篇关于安卓:FileObserver只监视顶级目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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