0

I'm new in android development and for now I would like to create an app that uses a SQLite DB. I'm having trouble to understand one thing about the PATH of the DB. I saw this on a guide to succeed in what I want, take a look:

    public class DataBaseHelper extends SQLiteOpenHelper{

        //The Android's default system path of your application database.
        private static String DB_PATH = "/data/data/YOUR_PACKAGE/databases/";

            private static String DB_NAME = "myDBName";


         ...
}

When it says path there, it's the path of the SQLite db file on my desktop? That's is gonna be used while I'm running at the AVD? And.. when I change the db to my tablet ("localhost" of the db this way) I need to specify the path inside my tablet?am I correct?

Victor Oliveira
  • 3,293
  • 7
  • 47
  • 77

1 Answers1

1

No, that path is the path to the location where your db will be located on the device. The DB is normally kept in a path containing your package name (which is secure and no other app can access unless the phone is rooted).

If your package name were "com.test.victor", the path to the DB on the device would be:

private static String DB_PATH = "/data/data/com.test.victor/databases/"; 

If you are not creating the DB from scratch via your app and would rather use a pre-created DB, you need to put that DB in your assets folder, and then copy the db to the proper directory to be used by Android when you start the app.

Here's a link to another question I recently answered addressing copying a database file from assets for use.

Community
  • 1
  • 1
Barak
  • 16,318
  • 9
  • 52
  • 84
  • thank you very mutch, wonderful help - Ps: I would like to vote up, but I can't since I dont have enough reputation – Victor Oliveira Aug 05 '12 at 17:09
  • You can accept the answer even if you can't upvote it yet. Just click the check mark next to the answer. That shows that your question is answered and gives the answerer some credit for helping out. (Accepting an answer also gives you a bump to your reputation). – Barak Aug 05 '12 at 17:16