以编程方式获取我的应用程序的数据库目录 [英] Get databases directory for my app programatically

查看:131
本文介绍了以编程方式获取我的应用程序的数据库目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的应用程式中使用「预先载入」的资料库。有很多关于这个问题,大多数指向这篇博客文章这里或类似的。

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),但是你需要给它一个现有的数据库名称和well ...它不存在,我想移动它: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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆