1

I am reading about Android and about how database is created and stored in application internal storage or sandbox.
Assuming I have created a database named "people.db" by calling SQLiteHelper.execSQL(peopleDB), how do I get this database file path and show it in a TextView?

To clarify, I am not asking how to create a database but how to get the path to my database file "people.db"?

String peopleDB = "people.db";

All I am trying to do is show in a Label where that application storage (or sandbox) is and to show my database location on device. This is just for personal learning, so I am not concerned about showing this information to the user or anything like that.

pixel
  • 9,653
  • 16
  • 82
  • 149

3 Answers3

4
File dir = getDatabasePath("people.db");
textView1.setText(dir.getAbsolutePath());

File explorer apps have no acces as its your app' private internal storage.

greenapps
  • 11,154
  • 2
  • 16
  • 19
2

You can find your created database, named

in

//data/data/<Your-Application-Package-Name>/databases/<your-database-name>

Use File explorer of DDMS to navigate to emulator directory.

Keyur Thumar
  • 608
  • 7
  • 19
  • I cannot navigate into that directory. I can go into first data but clicking on 2nd data shows nothing – pixel Apr 16 '17 at 17:21
  • Hey, thanks but that is not what I was asking. Anyways, much appreciated. The marked answer helped figure out and it turned out the correct path is /data/user/0/package-name/databases/people.db. However, it turns out I cannot navigate to this location using Android Device Monitor in Android Studio so I posted question re that at http://stackoverflow.com/questions/43440253/android-device-monitor-not-showing-content-of-data-user-where-my-database-is-sto – pixel Apr 16 '17 at 17:53
1

You can get path by context.getDatabasePath(DataBaseHelper.dbName)

It is already answered here Get database path

J.Krishna
  • 1,010
  • 2
  • 15
  • 21