gpt4 book ai didi

Android FileObserver 传递未记录的事件 32768

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:04:33 32 4
gpt4 key购买 nike

我正在使用 FileObserver观察目录的变化。该过程在 90% 的时间里运行良好,但偶尔会失败。

这是一个 logcat 的工作示例:

04-23 21:12:03.873: V/ItemObserver(1663): Setting up new item observer for item 2
04-23 21:12:04.374: I/ItemObserver(1663): Received item event for item 2, event: 256, file: batch.get.47
04-23 21:12:07.866: I/ItemObserver(1663): Received item event for item 2, event: 512, file: batch.get.47
04-23 21:12:07.873: I/ItemObserver(1663): Received item event for item 2, event: 512, file: item.xml
04-23 21:12:07.883: I/ItemObserver(1663): Received item event for item 2, event: 256, file: item.xml
04-23 21:12:08.033: I/ItemObserver(1663): Received item event for item 2, event: 8, file: item.xml

这是一个失败的例子:

04-23 22:08:09.403: V/ItemObserver(1751): Setting up new item observer for item 2
04-23 22:08:09.813: I/ItemObserver(1751): Received item event for item 2, event: 256, file: batch.get.52
04-23 22:08:09.954: I/ItemObserver(1751): Received item event for item 2, event: 32768, file: null

一旦我收到带有空文件的 32768 事件,一切都会停止。我检查了 FileObserver 的源代码并搜索了 inotify 32768,但找不到在任何地方引用它的地方。

设置观察者的代码如下:

itemDirObserver = new FileObserver(getItemsCache().getProcessedItemDir(itemId).getPath(), 
FileObserver.CLOSE_WRITE | FileObserver.CREATE | FileObserver.DELETE) {
@Override
public void onEvent(int event, final String file) {
itemDirChanged(event, file);
}
};
itemDirObserver.startWatching();

logcat 的代码是:

public synchronized void itemDirChanged(int event, String file) {
Log.i(LOG, "Received item event for item " + itemId + ", event: " + event + ", file: " + file);
switch (event) {
<snip>

知道 32768 和 null 文件代表什么吗?

最佳答案

感谢this answer .

列出事件代码here .

32768 特别是这个:

#define IN_IGNORED 0x00008000/* 文件被忽略 */

关于Android FileObserver 传递未记录的事件 32768,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10305054/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com