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

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

问题描述

我已经发现无法将文件捆绑在 .apk 中并将它们放在/sdcard 上,目前最好的选择是在第一次运行时下载大文件.我看到一个教程,说如何将 sqlite db 与 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/topic/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 包装器/框架来访问这样的数据库?

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天全站免登陆