Download SQLite database from Internet and load into Android application

后端 未结 3 1918
北荒
北荒 2020-12-23 23:55

For my android application, I would like to use a large database (about 45 MB).

One solution would be to include the (splitted) database in the assets folder and cop

3条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2020-12-24 00:19

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

    It would not have to be split, just ZIPped. See SQLiteAssetHelper for an example.

    How could I do this?

    Use HttpUrlConnection. Or, use HttpClient.

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

    Yes. Use getDatabasePath() to get the correct local path to use.

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

    You could, but for 45MB, that would be ghastly slow.

提交回复
热议问题