FileObserver does not work on external storage in Android 6.0 Marshmallow (API 23)

落花浮王杯 提交于 2019-12-20 16:20:29

问题


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.

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.

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

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

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

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

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

Did anybody test FileObserver considreing all of the following? :

  • 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).

回答1:


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

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.



来源:https://stackoverflow.com/questions/32354489/fileobserver-does-not-work-on-external-storage-in-android-6-0-marshmallow-api-2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!