質問

I've been reading about Content Providers and the Media Store but I'm still not sure what's the best way to solve this common problem.

To simplify, let's say I want to create an app to read ebooks. Users will copy their ebooks in the device storage somehow (i.e: using the USB and their computer, from dropbox, email...). Ebooks might be in several formats (mobi, epub,...). Since those files are not media files, I cannot use the Media Store for that purpose. It's also important to note, that I don't want a concrete solution for certain kinds of files (such as ebooks in my example). I would like a solution valid for all kind of files, even the most exotic ones.

I would like to perform a scan of the device storage to display a list of the ebooks saved in the device. I guess that should be done the first time the app is launched and afterwards if the user wants to update the list.

The problem I see is that the user may delete some of the ebook files outside my app, so it may show some old entries which are not there anymore. Of course I can show an error message if the user selects a removed entry, but maybe there is a better solution to that.

My question is basically what is the best strategy to keep the file list up to date. With "best strategy" I mean, to avoid potential critical errors and making everything as much transparent to the user as possible.

役に立ちましたか?

解決

I think showing an error message to the user when he selects a removed entry is currently the best approach. You can also start a background service to check the file list after the user started your app. In most cases the code will be faster than user's reactions. I think the app can update itself before the user interacts with data. Or you can show only a progress bar while updating the data, and show the data (books) when done.

Alternatively, there is FileObserver. But it is impossible, I think. You need a background service to watch for files. And that is not good for battery life and device's performance.

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