Download and replace Android resource files

ⅰ亾dé卋堺 提交于 2019-12-18 03:42:07

问题


My application will have some customisation for each company that uses it. Up until now, I have been loading images and strings from resource files. The idea is that the default resources will be distributed with the application and company specific resources will be loaded from our server after they click on a link from an email to launch the initialisation intent. Does anyone know how to replace resource files? I would really like to keep using resource files to avoid rewriting a lot of code/XML.

I would distribute the application from our own server, rather than through the app store, so that we could have one version per company, but unfortunately this will give quite nasty security warnings that would concern our customers.


回答1:


Does anyone know how to replace resource files?

It is not possible, except by deploying an updated APK. APKs are digitally signed and cannot be modified at runtime.




回答2:


No it is not possible, but here is what you can do instead... Copy your images etc in the Assets folder.. From the assets folder , copy them at runtime in the Application dir.. ie data/data/yourapppackage/yourresourcefolder Use the images etc from the runtime folder.. Ie In code say,.. imageView.setBackgroundDrawable(data/data/apppackagename/download/themename/resourcename)... Now when you download your resources from a runtime path , keep an XML file with key names and path for the image as key value pairs.. Have approprite Enums for that in code and store the image paths in HashMap at runtime..



来源:https://stackoverflow.com/questions/2823696/download-and-replace-android-resource-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!