我可以下载/ sdcard上的SQLite数据库,并从我的Android应用程序访问它? [英] Can I download an SQLite db on /sdcard and access it from my Android app?

查看:109
本文介绍了我可以下载/ sdcard上的SQLite数据库,并从我的Android应用程序访问它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经发现没有办法捆绑.apk中的文件,并将它们放在/ sdcard上,目前最好的选择是首次运行时下载大文件。我来到一个教程,说如何捆绑sqlite数据库与apk,然后复制它,以便它可以用SQLiteDatabase访问(因此加倍所需的空间,而不是使用/ sdcard)。

I already found out that there is no way to bundle files in an .apk and have them on /sdcard, the best option so far being to download the large files upon first run. I came accross a tutorial saying how to bundle an sqlite db with the apk and then copy it so that it can be accessed with SQLiteDatabase (thus doubling the space needed, and not using /sdcard at all).

http://developer.android .com / guide / topics / data / data-storage.html#db 表示所有数据库必须在/ data / data / package_name / databases中。

http://developer.android.com/guide/topics/data/data-storage.html#db says all databases MUST be in /data/data/package_name/databases.

这是真的吗?有没有办法欺骗框架打开放置在/ sdcard分区上的数据库?有没有办法使用另一个SQLite的java wrapper /框架来访问这样的数据库?

Is that really so? Is there a way to trick the framework into opening a database that is placed on the /sdcard partition? Is there a way to use another SQLite java wrapper/framework to access such databases?

如果上面的答案是否,我还有什么其他选择?我的数据在关系模型中很好地表示,但是太大了,另外,我希望能够更新它,而不需要重新安装/升级整个应用程序。

If the answer to the above is 'No', what other options do I have? My data is very well represented in a relational model, but is just too big, plus, I want to be able to update it without the need to reinstall/upgrade the entire app.

推荐答案

当然可以。文档有点相互冲突,因为他们也说没有任何限制。我认为他们应该说,相对路径是到上述位置和dbs有私人。这里是你想要的代码:

Sure you can. The docs are a little conflicting about this as they also say that no limitations are imposed. I think they should say that relative paths are to the above location and dbs there ARE private. Here is the code you want:

File dbfile = new File("/sdcard/mydb.sqlite" ); 
SQLiteDatabase db = SQLiteDatabase.openOrCreateDatabase(dbfile, null);
System.out.println("Its open? "  + db.isOpen());

这篇关于我可以下载/ sdcard上的SQLite数据库,并从我的Android应用程序访问它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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