FileObserver在Android 6.0 Marshmallow(API 23)中的外部存储上不起作用 [英] FileObserver does not work on external storage in Android 6.0 Marshmallow (API 23)

查看:226
本文介绍了FileObserver在Android 6.0 Marshmallow(API 23)中的外部存储上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,该应用程序使用 FileObserver 观察外部存储上的公共目录。
Lollipop 设备上可以正常工作。我想添加对棉花糖的支持,因此我为其设置了Nexus 9平板电脑。

I have an app that observes a public directory on external storage with FileObserver. It works fine on Lollipop devices. I want to add support for Marshmallow, so I set up a Nexus 9 tablet with it.

在棉花糖上设备,它失败,在Lollipop设备上可以。
在棉花糖设备上, FileObserver 不会对其他进程引起的文件系统事件作出反应。例如。截屏,通过 adb shell创建文件。
如果文件是由我的应用程序创建的,则效果很好。

On the Marshmallow device, it fails, on Lollipop device it's OK. On Marshmallow device, the FileObserver does not react to file system events that are caused by other processes. E.g. taking a screenshot, creating files via adb shell. It works fine if the files are created by my app.

棉花糖上,我要求 Manifest.xml WRITE_EXTERNAL_STORAGE READ_EXTERNAL_STORAGE 权限。

On Marshmallow, I ask for WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE permissions from Manifest.xml.

使用API​​ 23进行编译时,我还要确保调用 ActivityCompat.requestPermissions()

When I compile with API 23, I also make sure that I call ActivityCompat.requestPermissions().

当我使用API​​ 22进行编译时,我仅依赖于 Manifest.xml

When I compile with API 22, I just rely on Manifest.xml.

如果我观察到 / data / data / my-package-name 上的内容,它会起作用。

It works if I observe stuff on /data/data/my-package-name.

如果我在 / storage / emulated / 0 / Pictures / Screenshots 上观察到东西,就会失败。

It fails if I observe stuff on /storage/emulated/0/Pictures/Screenshots.

有人测试了 FileObserver 考虑以下所有内容? :

Did anybody test FileObserver considreing all of the following? :


  • 棉花糖设备

  • API 23和API 22?

  • 外部存储

  • 文件是由观察应用程序以外的其他进程创建的(例如 adb 或截屏)。

  • Marshmallow device
  • API 23 and API 22?
  • external storage
  • files created by some other process than the observing app (e.g. adb or taking screenshot).

推荐答案

这似乎是一个错误棉花糖,参见此链接

This appears to be a bug in Marshmallow, see this link.

即使在Nougat中也无法解决此问题,您可以删除整个FileObserver的API,因为它使在大多数设备上将无法工作的事实完全没有用。

This is not fixed even in Nougat, you could get rid of the API this whole FileObserver, as it makes completely useless the fact that on most of the devices, it will not work.

这篇关于FileObserver在Android 6.0 Marshmallow(API 23)中的外部存储上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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