I'm currently working on an app which downloads a zip file and extracts a bunch of tiny mp3 files into external storage. The zip file is about 2.5 meg.
I'm wondering if it would be a better idea to include the zi开发者_如何学Cp file in app resources, and then copy and extract it to the file system. This would prevent the headaches involved in something like a lost connection during the zip file download. I noticed some missing mp3s, and when I checked the zip file, the last 20 or so weren't it it. So, it looks like the system can successfully (an unfortunately) extract from an incomplete zip file.
The downside including the zip file in app resources is obviously that it increases the size of the app by 2.5 meg. I've specified "prefer external storage" in the manifest. This isn't supported before release 2.2, i.e. level 8, so I'm already excluding those phones, which probably is 20 or 30 percent of the total android phones. But I'm not entirely sure if that guarantees the app will be installed on the SD card.
It could be worth including the zip file in the app just to avoid the potential hassles in handling the download of the zip file; but if the size of the app makes it unappealing, then that's kind of a drawback - especially if the "prefer external" doesn't work on some devices.
Which is the better option? Ideas are welcome.
One of the highest selling Android Games, Gun Bros, does what you are thinking about: small app, that downloads the content on demand. This allows them to also serve ads while the content is downloading. In addition, by downloading the content you can make use of compression over the network thus reducing the total amount of data a user will actually have to use to get the whole application. I think in the end it is a personal preference, but I would lean towards downloading over the network.
Given the fact that there are some apps/games out in Android market which are in the 40+ MB range a 2 MB additional download doesn't seem that much to me. Anyway your users have to download it one way or another. Either in the apk or as a separate zip file.
Now Android market allows you to post updates to your application so your users can get new content through there.
Regarding prefer external storage, it is just that - a preference. If external storage is not available or a user is installing it on a 2.1 phone, then it will install the application to internal storage, as long as your applications minimum SDK level is 7 or lower.
But there are other applications I can think off that download content from sites, things like scripting for android (SL4A). If you want to update your game content that way, I would recommend creating a mechanism whereby your application can first discover the size of the download, then do the download. And once the download completes, verify the size against the size it should be. If the two don't match, then run the download again or something like that.
I'd recommend just including it in the apk file. Many apps on the market are like 5-10 MB, and games can be even bigger (I've seen games range anywhere from 1 MB to 40 MB), so adding 2,5 MB to your app shouldn't really be a problem, even if they don't support installing to sd-cards. My phone for example have 2.1 and therefor can't install to the sd-card and I've so far never run out of space even after installing a bunch of 2-5 MB apps.
And no "prefer external storage" does not guarantee that it's installed on the sd-card, if the user doesn't have an sd-card for example, or if they choose themselves to move it to the internal storage.
Point is, adding 2,5 MB to your apk isn't anything anyone will really notice or care about, and you shouldn't need to either.
精彩评论