android - 从 Internet 下载 SQLite 数据库并加载到 Android 应用程序中

标签 android sqlite download

对于我的 android 应用程序,我想使用一个大型数据库(大约 45 MB)。

一个解决方案是将(拆分的)数据库包含在 Assets 文件夹中,并在第一次启动时将其复制到数据库目录。

但这会占用磁盘空间两次 - 一次在无法删除文件的 Assets 文件夹中,一次在文件已复制到的数据库目录中。

所以我宁愿在第一次启动时从互联网(网络服务器)下载数据库。我怎么能这样做?我可以下载一个完整的SQLite文件并保存到数据库目录吗?还是我应该使用用于填充数据库的 JSON 数据文件?

最佳答案

One solution would be to include the (splitted) database in the assets folder and copy it to the database directory on the first startup.

不必拆分,只需压缩即可。参见 SQLiteAssetHelper举个例子。

How could I do this?

使用HttpUrlConnection。或者,使用 HttpClient

Can I download a complete SQLite file and save it to the database directory?

是的。使用 getDatabasePath()获取要使用的正确本地路径。

Or should I rather go with JSON data files that are used to populate the database?

你可以,但对于 45MB,那会非常慢。

关于android - 从 Internet 下载 SQLite 数据库并加载到 Android 应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10254872/

相关文章:

android - 多选微调器

android - 通过蓝牙从 Android 向 Arduino 发送字节会导致应用程序崩溃

java - 如何检查复选框是否在 Android 中被选中?

javascript - 在隐藏的 iframe : Android equivalent in Comet context? 中下载文件

android studio 无法解析 com.android.support :appcompat-v7:26. 1.0

Python sqlite3,从for循环插入数据

sqlite - 无法使用JOOQ更新SQLITE中的表行

iphone - HTML5 数据库验证表是否存在?

download - Google Play 商店中的下载次数是如何计算的?

c# - 如何在 C# 中获取像 IDM Grabber 这样的特殊网站的文件和文件夹