Android - APP 附加主题(图像、声音等)

发布于 2024-12-03 18:01:35 字数 341 浏览 2 评论 0原文

我是android开发的新手,这对大多数人来说可能是一个简单的问题,但似乎无法在互联网上找到答案。

如果我想向我构建的应用程序提供由新图像和声音组成的附加包,最好的解决方案是什么。我尝试阅读内容提供商,但问题多于答案。我有几个问题:

  • 这些图像可以动态放入原始应用程序的资源/可绘制文件夹中吗?
  • 我如何访问这些新图像? R.drawable 可以工作吗?
  • 如果我使用 SQLite 存储信息,我应该存储到实际图像或图像名称还是 R.drawable id 吗?

根据所选的主题,我希望我的原始附加组件和新附加组件都可以在应用程序中访问。

谢谢。

I am new to android development, probably an easy question to most, but can't seem to find the answer on the Internet.

If I want to provide add-on packages consisting of new images and sounds to the app I built, what is the best solution for that. I tried to read up on Content Provider, but have more questions than answers. Few questions I have:

  • Can these images be dynamically put into the original App's resource/drawable folder?
  • How can I access these new images? Would R.drawable work?
  • If am I storing the info using SQLite, should I be storing to actual image or image name or the R.drawable id?

Depending on the theme selected, I want both my original and new add-ons to be accessible in the app.

Thanks.

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

屌丝范 2024-12-10 18:01:35

在我开始实施之前,让我先回答你的问题:)

1) 不。 .apk 文件一旦创建,就无法修改其内容。这是因为应用程序经过数字签名,以防止恶意代码在应用程序内标记自身。
2)因此,您有两个选项来存储任何自定义插件。 1)外部存储(即用户的SD卡)或内部存储(即手机内存)每个应用程序至少有两个据我所知在手机内存中的文件夹,一个用于数据库(这就是为什么你可以修改sqllite数据库),另一个用于通用文件。由于这些文件在编译时并不“已知”,因此您无法通过 R.drawable 访问它们。
3)好吧,鉴于上面的信息,我认为您可能希望在表中包含图像名称:)

所以,现在让我们在这里更具体一些。我只是想就如何实施这个项目提出一些粗略的想法。当然,您可以随意调整它以满足您的需求。

首先,我会决定在哪里放置插件。每个位置都有起伏。如果插件存储在本地内存中,无论用户是否有 SD 卡,您的主题都将可用。但另一方面,许多用户似乎抱怨应用程序占用大量手机内存空间,即使有时他们是下载大量额外内容的人。使用 SD 卡方式,您可能应该在手机内存中保留对默认主题或基本插件的引用,以便在 SD 卡无法安装或其他情况下至少有一些东西。确保在尝试从 SD 卡加载任何内容之前先检查 SD 卡是否存在。将其放在 SD 卡上的一个好处是用户可以轻松地直接从计算机下载插件并将其直接放入应用程序文件夹中。我个人会推荐这种方式,但请确保您的 Android Manifest 文件包含该权限,否则! :)

需要注意的是,将应用程序移至 SD 卡(Android 2.2 中的一项功能)和将文件放在 SD 卡上是有区别的。移动到 SD 卡的应用程序仍然可以以相同的方式访问“内部存储”,但实际位置位于 SD 卡上。一开始我很难理解的是,移动到 SD 卡的应用程序的功能与移动到手机内存中的功能相同。如果您打算将所有内容保存在手机内存中,了解这一点很重要,因为 Android 2.1 用户可能会抱怨尺寸过大,而 2.2 用户可以将其移动到 SD 卡上。 (这也是您应该在 android 清单文件中设置的内容)

因此要考虑的另一件事是如何引用每个主题。首先,谁将制作这些插件?任何有兴趣制作插件的人都可以访问模板吗?如果您希望插件系统更加公开,那么您可能希望您的存储具有目录结构类型的感觉,

-themes
|
---MyTheme
|
-----icon.jpg
-----blah.mp3
----- ... and so forth

这样您就可以强制执行严格的命名约定,或者您可以允许他们想要的任何名称,但要求他们将其列出在您要解析的 XML 文件中。我认为严格的命名系统是一个稍微好一点的方法。也许仍然可以包含一个 XML 文件来获取额外信息(根据需要),无论哪种方式,将来都可以节省大量时间来保持插件整洁有序。

事实上,我现在有点累了,因为已经很晚了,但这里有一些很好的读物,可以帮助你在这个问题上找到正确的方向。

http://developer.android.com/guide/topics/data/data -storage.html

http://www.helloandroid.com/tutorials/how-download-fileimage-url-your-device

http://www.jondev.net/articles/Unzipping_Files_with_Android_%28Programmatically%29

最后要注意的是,ContentProvider 用于在应用程序之间发送数据,并且在持久数据存储方面实际上并不有效。 ;)

Before I get into implementation, lemme first answer your questions :)

1) Nope. You cannot modify the contents of a .apk file once it has been created. This is because the app is digitally signed to keep malicious code from tagging itself inside the app.
2) So because of that you have two options for storing any custom addons. 1) External Storage (ie the user's SD Card) or internal storage (ie the phone memory) Each application is given at least two folders that I know of in the phone memory, one is for databases (which is why you can modify the sqllite databases) and the other is for generic files. Since these files are not "known" at compile time, you cannot access them by R.drawable.
3) Well, given the information above, I think that you would probably want the image name inside the table :)

So, now lets get a little more specific here. I'm just going to throw out some rough ideas on how I would implement this project. Feel free to adapt it to your needs of course.

For starters, I would make a decision on where to locate the addons. Each location has ups and downs. If the addons are stored in local memory, your themes will all be available whether or not the user has an SD Card in. But on the other hand, many users seem to complain about apps that take up lots of phone memory space, even if sometimes they are the ones who downloaded tons of extra. With the SD Card way, you should probably keep a reference to a default theme, or basic addons inside the phone memory so there is at least SOMETHING there if their sd card fails to mount or what not. Make sure that you check for the existence of the sd card first before trying to load anything from there. A benefit of putting it on the sd card is users are easily able to download addons straight from their computer and put them into the app folder directly. I personally would recommend this way, but make sure your Android Manifest file includes that permission or else! :)

One note is that there is a difference between an application moved to the SD card (a feature in Android 2.2) and putting files on the SD card. An application that is moved to the SD card still has the "internal storage" available to access in the same way, but the actual location is on the SD card. That was difficult for me to understand at first was that an app moved to the sd card functions the same way as if it was in the phone memory. That is important to understand if you plan to save everything in the phone memory since Android 2.1 users might complain about large sizes, whereas 2.2 users can just move it to the SD Card. (This is also something you should set in the android manifest file)

So another thing to consider is how to reference each theme. First off, who will be making these addons? Will any person who is interested in making a plugin have access to a template to do so? If you want the addon system to be more public, then you'll probably want to have a directory structure type feel to your storage

-themes
|
---MyTheme
|
-----icon.jpg
-----blah.mp3
----- ... and so forth

With that you can either enforce a strict naming convention or you can allow whatever they want names, but require them to list it in an XML file that you would parse. I think a strict naming system is a slightly nicer approach though. Maybe that can still include an XML file for extra information (as needed) Either way, it will save a lotta time in the future to keep the addons neat and orderly.

I'm actually kinda tired right now cause its really late at night, but here are some good reads to help steer you in the right direction on this matter.

http://developer.android.com/guide/topics/data/data-storage.html

http://www.helloandroid.com/tutorials/how-download-fileimage-url-your-device

http://www.jondev.net/articles/Unzipping_Files_with_Android_%28Programmatically%29

And one last quick note, ContentProvider is used to send data between applications and really isn't effective at persistent data storage. ;)

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文