質問

I need to be able to track additions/deletions of Documents to the android file system. By Documents, I mean files like word, excel, powerpoint and pdf, for now. I am aware of ContentProviders and ContentObservers. As far as ContentObserver's are concerned, I see that I can set up a ContentObserver for media file type i.e. Audio, Video and Photos. However, I do not see something that could tell me about Document types.

One possibility is I install a ContentObserver for all files (including media), but I am worried about what it would do to performance. I ask because I see people are already complaining about android scanning the entire file system for changes to media files. I have become aware of the .nomedia workaround which people use to have android skip certain folders from ContentObserver changes.

I am looking for two answers:

  1. Is there a more efficient way to achieve what I want without watching for changes for all files? Something like a Documents ContentObserver.

  2. Another thing is, when I open "My Files" on an android device, I see among the other media types a Documents entry at the top level. Does anyone know how this is achieved?

役に立ちましたか?

解決

I need to be able to track additions/deletions of Documents to the android file system.

Why is this in the user's interest? Remember: you are not important; your user is.

I am aware of ContentProviders and ContentObservers.

Note that these only work while your app is in memory for other reasons.

I see that I can set up a ContentObserver for media file type i.e. Audio, Video and Photos. However, I do not see something that could tell me about Document types.

Correct, because there is no "Document types" in Android. This is your own invention. You could just as easily be referring to "Snicklefritz types", defined as "files whose 18th byte is 0x4F".

Is there a more efficient way to achieve what I want without watching for changes for all files?

Not really. You are welcome to use FileObserver to monitor changes to a file or a directory, but that will only be for that file or that directory, not the entire filesystem.

when I open "My Files" on an android device

There is no "My Files" in Android. There may be something called this on your specific Android device, running your specific firmware.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top