The database used by this app was created by hand using
sqlite3
before the app was written.
To read the database,
the app uses the third-party class
SQLiteAssetHelper
,
which is a subclass of Android’s class
SQLiteOpenHelper
.
It opens an SQLite
.db
file in the
databases
subfolder of the app’s
assets
folder.
MainActivity.java
.
The
SimpleCursorAdapter
uses
simple_list_item_2.xml
.
Helper.java
:
defines a subclass of
SQLiteAssetsHelper
.activity_main.xml
.
The
RelativeLayout
displays a
ListView
when the table is non-empty,
and a
TextView
when the table is empty.
strings.xml
stooges.db
(not humanly readable)
AndroidManifest.xml
build.gradle
(Module: app).
I added
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'
to the dependencies.
cd ~/Desktop pwd sqlite3 stooges.db sqlite> create table android_metadata ( locale text default "en_US" ); sqlite> .schema android_metadata sqlite> insert into android_metadata (locale) values ("en_US"); sqlite> select * from android_metadata; en_US sqlite> create table people ( _id integer primary key autoincrement, name text ); sqlite> .schema people sqlite> insert into people (name) values ("Moe"); sqlite> insert into people (name) values ("Larry"); sqlite> insert into people (name) values ("Curly"); sqlite> insert into people (name) values ("Shemp"); sqlite> select * from people; 1|Moe 2|Larry 3|Curly 4|Shemp sqlite> .quit ls -l stooges.db -rw------- 1 myname mygroup 5120 Jul 24 21:18 stooges.db sqlite> file stooges.db stooges.db: SQLite 3.x database
Select the
app
folder at the top of the Android Studio
project
view
and pull down
File → New → Folder → Assets Folder
Finish
Select the
app/assets
folder you jsut created in the Android Studio
project
view
and pull down
File → New → Folder → Assets Folder
☑ Change Folder Location
New Folder Location: src/main/assets/databases
Finish
Control-click on the
stooges.db
on your Desktop and select Copy “stooges.db”.
Then control-click on
app/assets/databases
and select Paste.
Press OK.