Android:将带有数据文件的预加载数据库公开为 ContentProvider

发布于 2024-12-01 08:47:15 字数 785 浏览 6 评论 0 原文

我必须将一个文件夹与我的 Android 应用程序捆绑在一起。该文件夹将包含以下内容: 1. 带有预填充数据的 sqlite 数据库 - 例如音乐数据库。 2.一些声音文件

数据库应该如何将列链接到这些声音文件(最好是相对路径)。 我必须通过内容提供商将此数据库和声音文件公开给其他应用程序。

我在资产文件夹中建立了一个简单的数据库,并将其公开为内容提供者。我被困住的是 mp3 部分。如何使用内容提供程序将声音文件公开给其他应用程序?

我不想将声音文件作为数据块存储在数据库中。

我在这里找到了一些信息 http://www.techjini.com/blog/2009/01/10/android-tip-1-contentprovider-accessing-local-file-system-from-webview-showing-image-in- webview-using-content/ 但想知道如何将我的文件首先发送到应用程序内部空间(如果我必须这样做)。

我是否必须执行 Uri.create,打开流,然后将已经存在的文件(在我的资产文件夹/甚至 SD 卡中)一一复制到另一个位置,比如我的应用程序空间? (我可能有 1000 个文件!)

感谢您的帮助!

  • 尼米

I have to bundle a folder with my android app. This is what the folder will have:
1. a sqlite database with pre-populated data - say a music DB.
2. a few sound files

The database should some how link a column to these sound files(preferably relative paths).
I have to expose this db and the sound files to other apps through a content provider.

I got a simple db up in my assets folder and exposed it as a content provider. Where I am stuck is the mp3 part. How do I get to expose the soundfiles to other apps using a content-provider?

I do not want to store the sound files as data blobs in the DB.

I found some info here http://www.techjini.com/blog/2009/01/10/android-tip-1-contentprovider-accessing-local-file-system-from-webview-showing-image-in-webview-using-content/ But wondering how I can get my files to the app internal space in the first place(if i ever have to).

Do I have to do Uri.create, open the stream and then copy the already existing files (in my assets folder/or even the sdcard) one by one to another location, say my application space? ( I might have a 1000 files!)

thanks for any help!

  • nimmi

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文