从服务器发送 .zip 到 Android 应用程序的最佳方式
我正在设计一个应用程序,它将从服务器检索 .zip 文件并在接收时将它们提取到 SD 卡。
我想我可以弄清楚提取的过程,但我不确定从服务器发送 .zips 的最佳方式是什么。目前它只需要是一种方式,但将来我想添加版本控制(如果这很重要)。
我做了一些研究并查看了 JSON,但我找不到任何发送 .zip 文件的示例。 http 连接似乎是一个类似的选项,我知道我可以接收 .zips,但我认为版本控制不会那么容易实现。对于这两种方法中的任何一种的任何建议,或者如果您认为另一种方法会更好,我也愿意接受。
I am designing an application that will retrieve .zip files from a server and extract them to the sdcard on reception.
I think i can figure out the extracting, but I am not sure what the best way to send the .zips from the server is. It only need to be one way for now but in the future I would like to add version control if that matters.
I did some research and looked into JSON but I could not find any examples of that sending .zip files. A http connection seems like a comparable option and I know I could receive .zips but I don't think version control would be as easy to implement. Any suggestions for either of these two methods or if you think another way would be better, I'm open to that too.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用清单文件并首先获取它。检查清单文件(包含其他文件列表的文件)并查看本地存储是否包含这些文件。如果是的话——每个人都很高兴。如果没有,则将清单列出的文件获取到本地存储中。
不要直接使用上面提到的代码。使用一些 UI 反馈告诉用户您正在下载一些文件(最好先询问他们,以防他们想要切换到 wifi)。首先获取清单是可以的,只是不要在没有询问的情况下获取丢失的文件。
我为我的游戏“条形码野兽”执行此操作,该游戏在首次运行时下载约 20Mb 的音频资源。我还可以添加更多音频位,而无需推出新版本。 Android 也足够聪明,可以解压缩 zip 文件,但同样,请确保您告诉用户正在发生什么,并让他们能够取消或返回,而不会杀死您的主活动线程。
Use a manifest file and get that first. Examine the manifest file (a file that contains a list of other files) and see if your local storage contains those files. If it does - everybody's happy. If it doesn't then get the files that your manifest lists onto your local storage.
Don't use the code as mentioned above directly. Use some UI feedback to tell the user that you're downloading some files (and preferably ask them first in case they want to swap to wifi). Getting the manifest first is ok, just don't get the missing files without asking them.
I do this for my game "barcode beasties" which downloads approx 20Mb of audio assets on first run. I can also add further audio bits without having to push out a new release. Android is also clever enough to unzip zip files, but again, make sure you are telling the user what's happening and give them the ability to cancel or back without killing your main activity thread.
我认为你可以在android网站上使用标准的
HttpUrlConnection
,然后给它一个指向服务器上的zip文件的URL
。然后您只需将其下载到设备上的本地文件夹即可。
下面是我如何下载 Excel 文件的示例(zip 和 excel 文件都是二进制文件 - 所以它应该是相同的)。
当您想要进行某种版本控制时,您最好在服务器端(如果可能)使用服务器提供的任何内容(例如 php)进行此操作。
然后编写一个小的 php 脚本来检查可用 zip 文件的版本并发送响应(可能是 json 响应)。
I think you can use a standard
HttpUrlConnection
on the android site and just give it aURL
that points to your zip File on the server.Then you can just download it to a local folder on the device.
Here is an example for how I download Excel files (zip and excel files are both binary - so it should be the same).
When you want to do some sort of version control you are probably better off doing this on the server side (if possible) with whatever the server offers (e.g. php).
Then make a small php script that checks the version of the available zip files and send a response (maybe a json response).