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

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

问题描述

根据文档,

"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."

我的代码是这样的,

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

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

但是,onEvent() 仅在 /mnt/sdcard/ 中的文件发生更改时触发.如果我在 /mnt/sdcard/downloads/ 中创建一个文件,该方法不会被触发.

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.

代码有问题吗?

推荐答案

根据文档

文档不正确,如此问题中所述.

代码有问题吗?

不,但是 FileObserver 不是递归的,尽管文档相反.

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

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

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