以编程方式获取我的应用程序的数据库目录 [英] Get databases directory for my app programmatically
问题描述
我想在我的应用程序中使用预加载"数据库.关于此问题有很多问题,大多数指向此博客文章
I want to use a "pre loaded" database in my app. There are tons of questions about this and most point to this blog article here or similars.
到目前为止,一切都很好.我只想知道是否有更好的方法来获取默认的数据库目录,因此您不必使用以下方法:
So far so good. I just want to know if there is a better way to get the default databases directory so you don't have to use something like this:
private static String DB_PATH = "/data/data/YOUR_PACKAGE/databases/";
我的意思是,也许将来会有所改变,或者某个设备或rom可以将其放置在其他地方...那么有没有办法以编程方式获取此路径?
I mean, maybe that is changed in the future or maybe a device or rom could place it elsewhere... so is there a way to get this path programatically?
在上下文中,存在一种获取getDatabasePath(name)的方法,但是您需要给它一个现有的数据库名称,好吧...它尚不存在,我想将其移动到那里:P
In Context exists a method to getDatabasePath(name), but you need to give it an existing db name and well... it doesn't exist yet, I want to move it there :P
推荐答案
创建一个空的DB,用getDatabasePath()
获取路径,然后用您自己的路径覆盖.
Create an empty DB, get the path with getDatabasePath()
, then overwrite it with your own.
这篇关于以编程方式获取我的应用程序的数据库目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!