Include A Data File With My Android App
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
Solution 1:
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:
Describe preferences in xml --- store in RES/XML:
<?xml version="1.0" encoding="utf-8"?><PreferenceScreenxmlns:android="http://schemas.android.com/apk/res/android"><PreferenceCategory ><CheckBoxPreference /></PreferenceCategory></PreferenceScreen>
Load for sure onCreate():
/* Loading default preferences the first time application is run */
PreferenceManager.setDefaultValues(getApplicationContext(),
R.xml.generalsettings, false);
Else,
You can hardcode data and store in the db:
String sql= "CREATE TABLE ..." + "INSERT VALUES ... INTO ... ";
db.ExecSQL(sql);
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:
InputStreamis= context.getResources().openRawResource(R.raw.artoodict);
BufferedReaderbr=newBufferedReader(newInputStreamReader(is));
StringreadLine=null;
try {
while ((readLine = br.readLine()) != null) {
}
}
} catch (IOException e) {
e.printStackTrace();
}
Post a Comment for "Include A Data File With My Android App"