Responding back to list.

31.03.2011 2:00, fg1921 пишет:
Yes, you can create yourdatabaseanywhere usingSQLitetools, and
package it with your application (assets / raw).

The first the app is run, open the packageddatabaseas a stream, and
copy it into a file where your application has read/write access.

This can be the memory card or the path returned by
Context.getDatabasePath(). If it's the latter, you'll then be able to
use SQLiteOpenHelper to open thedatabase.

So if we were to copy it to the SD Card, how would we then read it (if
we can't use SQLiteOpenHelper)?

SqliteOpenHelper uses Context.openOrCreateDatabase, so the database is always placed under the application's private data files directory.

To open a database file located on the memory card, you can use SQLiteDatabase.openOrCreateDatabase directly, supplying a full path.

The logic for onCreate / onUpgrade is in SQLiteOpenHelper, so if you need those, implement them yourself. You will then have a class similar to SQLiteOpenHelper, but able to open database files in external storage.

Also consider that files located on the memory card are available to any application and the user; this can be a security issue in some cases.

How does one read the database when
opened as a stream?


I meant you copy a database file (prepackaged with your application) from one location to another just like any other file, by treating it as a stream of bytes, rather than a database.

Open the source file with this:

http://developer.android.com/reference/android/content/res/AssetManager.html#open(java.lang.String)

The destination file with this:

http://developer.android.com/reference/java/io/FileOutputStream.html

and then perform the copy by reading data from one and writing to the other.

--
Kostya Vasilyev -- http://kmansoft.wordpress.com

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

Reply via email to