与APK分发分贝? [英] Distribute db with apk?

查看:136
本文介绍了与APK分发分贝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从开发指南使用SQLite数据库...


  

推荐的方法来创建一个新的SQLite数据库是创建SQLiteOpenHelper的子类,并重写onCreate()方法,您可以在其中执行命令的SQLite数据库中创建表格。


这是一般的'唯一'的方式来做到这一点还是有可能包括pre-创建空的(甚至是部分填充)DB与APK分配?很显然,我可以在我的电脑设计我的数据库,然后就产生了CREATE TABLE字符串和剪切/粘贴到我的strings.xml,但我想知道这可能会节省额外工作的替代方法。

编辑:在KevinDTimm的回答来看,假设这是可能的,我怎么包括与我的apk分布pre-创建的SQLite数据库?任何示例/指针感激地接受。

感谢。


解决方案

  

该方法我要告诉你需要自己的SQLite数据库文件
  从资产文件夹的副本
  进入系统数据库的路径
  应用这样SQLiteDatabase API
  可打开并正常访问它。


有一个看看这里:使用您在你的Andr​​oid应用程序的SQLite数据库

From the Dev Guide for using SQLite databases...

The recommended method to create a new SQLite database is to create a subclass of SQLiteOpenHelper and override the onCreate() method, in which you can execute a SQLite command to create tables in the database.

Is this generally the 'only' way to do this or is it possible to include a pre-created empty (or even part populated) db with an apk distribution? Obviously, I can design my database on my PC and then just generate the 'CREATE TABLE' strings and cut/paste into my strings.xml but I was wondering about alternative approaches which might save the extra work.

EDIT: In light of KevinDTimm's answer, assuming this is possible, how do I include a pre-created SQLite db with my apk distribution? Any examples/pointers gratefully received.

Thanks.

解决方案

The method I'm going to show you takes your own SQLite database file from the "assets" folder and copies into the system database path of your application so the SQLiteDatabase API can open and access it normally.

Have a look here : Using your own sqlite database in your Android applications

这篇关于与APK分发分贝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆