包括与我的Andr​​oid应用程序的数据文件 [英] Include a data file with my Android app

查看:167
本文介绍了包括与我的Andr​​oid应用程序的数据文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创造,我想用一个数据文件,应用程序将作为初始状态下使用种子的应用程序。在Eclipse项目结构,我在哪里添加数据文件,以便当应用程序部署到设备(和仿真器)中的数据文件部署呢?

I'm creating an app that I want to seed with a data file the app will use as its initial state. In the Eclipse project structure, where do I add the data file so that when the app is deployed to the device (and emulator) the data file is deployed with it?

推荐答案

这将有助于它可以将数据文件类型和目的。如果您正在寻找initalize某些设置,你可以做到这一点通过:

It will be helpful it you can the data file type and the purpose. If you are looking to initalize certain settings you can do it through:

描述preferences在XML ---店RES / XML:

Describe preferences in xml --- store in RES/XML:

<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <PreferenceCategory >
        <CheckBoxPreference  />
    </PreferenceCategory>
</PreferenceScreen>

负荷肯定的onCreate():

Load for sure onCreate():

/* Loading default preferences the first time application is run */
        PreferenceManager.setDefaultValues(getApplicationContext(),
                R.xml.generalsettings, false);

否则,

您可以硬code数据并存储在数据库中:

You can hardcode data and store in the db:

String sql = "CREATE TABLE ..." + "INSERT VALUES ... INTO ... ";
db.ExecSQL(sql);

否则你可以存储在Assets文件夹和使用getAssets)这个文件(恢复的文件:

Else you can store this file in the Assets folder and use getAssets() to retrieve the file:

        getAssets().open(fileName)

例如。使用原始数据文件。在资产的情况下,上述命令替换:

Eg. using raw data file. In case of assets replace with above command:

      InputStream is = context.getResources().openRawResource(R.raw.artoodict);
    BufferedReader br = new BufferedReader(new InputStreamReader(is));
    String readLine = null;

    try {
        while ((readLine = br.readLine()) != null) {

            }
        }
    } catch (IOException e) {
        e.printStackTrace();
    }

这篇关于包括与我的Andr​​oid应用程序的数据文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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