Sagar Zala
Sagar Zala

Reputation: 5134

SQLite Database found in different directory

Generally SQLite database is locate in /data/data/PACKAGE-NAME/databases/DBNAME but I found database in /data/user/0/PACKAGE-NAME/databases/DBNAME path in one device.

So, why this happened in single device?

Thanks.

Upvotes: 1

Views: 1669

Answers (1)

shizhen
shizhen

Reputation: 12583

You should programatically get the database file path rather than use a hardcoded manner. See API doc for getDatabasePath ; E.g.

// for `Activity`, `Service`. Otherwise simply get the context.
Context context = this;
String dbname = "dummy.db";
String dbpath = context.getDatabasePath(dbname).getPath();
Log.d("MY_TAG", dbpath);

enter image description here

If you want to get the database folder path, use getParent() like below:

String databaseFolderPath = context.getDatabasePath(dbname).getParent();

Upvotes: 3

Related Questions