android预填充sqlite数据库

我的应用程序中有一个sqlite数据库.我的应用程序不应将其作为空数据库发送,但在用户第一次使用该应用程序之前,需要创建某些记录.当然我可以有很多插入语句,但这似乎很奇怪.我想到像http://vineetyadav.com/tutorials/11-adding-prefilled-sqlite-database-to-android-app.html这样的东西基本上可以工作,但这意味着我手动创建的数据库也需要所有内部表,如android_Metadata.所以我要么知道内部表存在什么以及如何填充它们.或者另一种拥有预填充数据库的智能方法.有什么建议?

谢谢.

解决方法:

您可以从SD卡读取一个平面文件,每行插入1个语句并遍历该文件.

这是一个类似的例子,我在其中读取文件并将ContactItem添加到我的contact_list:

public ArrayList<ContactItem> readInputFile(Context context, String filename) {
    String text = null;
    BufferedReader reader = null;
    ArrayList<ContactItem> contact_list = new ArrayList<ContactItem>();
    contact_list.clear();  // Clear any existing contacts when a new file is read
    try {
        reader = new BufferedReader(new FileReader(filename));
        // Repeat until EOF
        while (((text = reader.readLine()) != null)) {
            if (!(text.length() > 1024)) {  //  If we read more than 1k per line there's a problem with the input file format
                ContactItem c = new ContactItem(text);
                if (c.getIsValid()) {
                    //  We were able to parse a well formed phone number from the last line read
                    contact_list.add(c);
                }
            }
        }
    } catch (FileNotFoundException e) {
        Toast.makeText(context, R.string.error_fileNotFound, 1).show();
        e.printstacktrace();
    } catch (IOException e) {
        Toast.makeText(context, R.string.error_ioException, 1).show();
        e.printstacktrace();
    } finally { // EOFException (or other, but EOF is handled and most likely)
        try {
            if (reader != null) {
                reader.close();
            }
        } catch (IOException e) {
            Toast.makeText(context, R.string.error_generalFailure, 1).show();
            e.printstacktrace();
        }
    }
    return contact_list;
}

相关文章

SQLite架构简单,又有Json计算能力,有时会承担Json文件/RES...
使用Python操作内置数据库SQLite以及MySQL数据库。
破解微信数据库密码,用python导出微信聊天记录
(Unity)SQLite 是一个软件库,实现了自给自足的、无服务器...
安卓开发,利用SQLite实现登陆注册功能