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,...

问题:

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.


回答1:

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();
  • 发表于 2019-03-15 00:11
  • 阅读 ( 61 )
  • 分类:sof

条评论

请先 登录 后评论
不写代码的码农
小编

篇文章

作家榜 »

  1. 小编 文章