开发者

Android - Add-on themes (images, sounds, etc) to APP

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开发者_StackOverflow社区 app.

Thanks.


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. ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜