I wasn't able to get the thumbnail view for a folder working. Instead, I managed something almost as good by launching the gallery on the first image in the folder.
Here's a description of what I wanted to accomplish. A user selects a specific record from a list view. This record can have a few images associated with it. I wanted to be able to browse these images using the cool Gallery3D app on the Nexus One (now with multitouch zoom!). If the images for that record are not already cached on the device's sdcard I'll download them as a zip file. I then extract that file to a cache dir for that record on the sdcard. Afterwards, I wanted to launch the gallery and only display the images in that cache dir.
Performing the download and extracting the zip file to the sdcard was not a problem. But, in order to get the gallery working, I had to use the MediaScannerConnection with a MediaScannerConnectionClient. After getting the scanner to connect (which was kind of flakey), I looped through all the files in the cache dir calling scanner.scanFile.
The MediaScannerConnectionClient#onScanCompleted would append the resulting uri's to an ArrayList member variable. When the whole process was done I'd launch the gallery passing the first uri in that list. This would view the first image in the directory. I would've preferred the thumbnail view but this is good enough.
I'm not totally comfortable with this solution. It seems that the MediaScannerConnection works asynchronously so my AsyncTask does a poll/sleep to see if it's done scanning.
Has anyone else had issues with the MediaScannerConnection not connecting on the first call? To work around this I'm doing something like:
MediaScannerConnection scanner = ...;
for (int attempts = 0; attempts < MAX_ATTEMPTS; attempts++) {
scanner.connect();
if (scanner.isConnected()) { break; }
else {
try { Thread.sleep(5); }
catch (Exception e){}
}
}
if (!scanner.isConnected()) {
throw new IllegalStateException("Unable to establish media scanner connection!");
}
Ugly I know but I'm not sure why it has trouble connecting the first time. :-/
UPDATE:
Thanks to jeffamaphone, I was able to dump that ugly code. Now the OnItemClickListener just calls scanner.connect(). The client that is passed to the scanner's constructor initializes the DownloadAsyncTask which updates a ProgressDialog as it unzips the files and calls scanner.scanFiles(...);