http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/
这家伙讲android系统路径:
//你的应用程序数据库的Android默认系统路径。
私有静态字符串 DB_PATH = "/data/data/YOUR_PACKAGE/databases/";
在这里: DB_PATH = "/data/data/com.android.example/databases/" 在有关 sqlite 数据库的许多其他链接中。
问题是,eclipse(在mac osx 10.7上)没有创建数据目录,而在我的motorola xoom(有Android 4.0.3 - 冰淇淋三明治)上,我无法确定它的默认系统路径是什么。我没有看到任何关于 /data/data/... 使用 Astro 文件管理器的内容。
由于我使用的是 mac,我不得不使用 android 文件系统应用程序将我的 apk 文件从我的 eclipse 工作区传输到 motorola xoom。我想我的一个问题应该是——在哪里放置这个或重要的地方是什么?
我已经下载了 Sqlite 数据库浏览器,并按照上面的链接填写了我的数据库。我没有任何主键。我已将 .db 文件复制到项目中的资产文件夹中 - 也如链接所述。
另外,由于我的数据库已经创建了表,所以我需要做的(我猜)就是将表复制到每个人都提到的那个数据目录,然后我应该能够进行插入/更新/选择等操作?
到目前为止我的代码:
public class DatabaseHelper extends SQLiteOpenHelper {
private Context myDbContext;
private static String dbName = "restaurant";
public DatabaseHelper(Context context){
super(context, dbName, null, 1);
this.myDbContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
//need to take input from local database and copy it
//but where do i copy the information to? what path should i use?
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
Log.w(DatabaseHelper.class.getName(), "upgrading database/changing database which will remove all old data!");
db.execSQL("drop table if exists menu");
db.execSQL("drop table if exists items");
db.execSQL("drop table if exists server");
onCreate(db);
}
}