获取数据库目录我的应用程序编程 [英] Get databases directory for my app programatically
问题描述
我想用一个装pre数据库在我的应用程序。有吨关于这个问题,大部分指向这个博客的文章<一个href="http://www.reigndesign.com/blog/using-your-own-sqlite-database-in-android-applications/">here或同类者。
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(名称),但你需要给它现有的数据库名称和幸福......它还不存在,我想将它移到那里: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
THX提前!
推荐答案
创建一个空数据库,获得与的路径getDatabasePath()
,然后用自己的覆盖。
Create an empty DB, get the path with getDatabasePath()
, then overwrite it with your own.
这篇关于获取数据库目录我的应用程序编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!