问题描述:

I have an existing database which I want to use in an android application.

I understand that I should place the database in the assets folder and then create a databasehelper.

However, about every single tutorial mentions that I need the path to my database in this Helperclass.

How do I find that?

Especially if I am using only a virtual device?

The rest SEEMS quite selfexplaining but this?

网友答案:

its in /data/data/packageName/databases use file explorer from DDMS.

OR

You can use:

String DB_PATH = "";
if(android.os.Build.VERSION.SDK_INT >= 17){
   DB_PATH = context.getApplicationInfo().dataDir + "/databases/";         
}
else
{
   DB_PATH = "/data/data/" + context.getPackageName() + "/databases/";
}

For Jellybean 4.2 multi users:

DB_PATH = "/data/data/" + context.getPackageName() + "/databases/"; 

to:

DB_PATH = context.getApplicationInfo().dataDir + "/databases/"; 
相关阅读:
Top