Download and replace Android resource files - android

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.

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.

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

Related

where to place the html,java script files other than assets in android

can we add the html and java script code anywhere other than assets folder in android which will used in web View, and it cannot be a URL also since it should work offline, because when we place the .html,java script etc in assets it can be easily found when we unzip the apk.
Kindly advice me in this regard.
Thanks
Nagendra.
You can put them in drawable or values folder as well.
Yes you can put them in /drawables/raw folder and you can access them like mentioned in Load html files from raw folder in web view. If you talk about unzipping or even reverse engineering for that matter, the java code, layout files all can be reverse engineered, sometimes even if you obfuscate the code. I would suggest you to store all sensitive data on a servers and then get it on runtime in the app.

Android Expansion apk

I was going through the docs of APK EXPANSION FILES in android and I was wondering that can we have all layout files in the patch apk and application's business logic in main apk ?
I read this Android Apps Break the 50MB Barrier too.
I tried creating this but the problem I faced was our widget names need to be in R.java file which is generated automatically..If I have layout files in patch file not in the main file then I am unable to refer then using R.id.xxx.
So Please tell me if this is possible or not ?
If this is possible then how it can be achieved ?
I also want to know ,what are the resources or assets that can be added in the patch apk.
Speaking straight, It's not possible to separate the layout files from apk and then trying to access it using R.id.whatever
Expansion files are meant to store the assets such as media, docs, and other such static things which your application uses and the content of the expansion pack is stored on device's shared storage and is not linked with the apk file. To access the assets of the expansion file, you must code your application to read them from that device's shared storage location.
Coming back to the question of storing the layout files in an expansion file. To achieve this, you will have to write your own layout parser with the basic functionality similar to LayoutInflator. You can not use LayoutInflator to parse any layout file which is not part of the apk or stored on any external storage. So the idea is to store your layout files in the expansion file (which will be out of apk, on device shared storage), parse the file using your own parser, and add the views to the main layout at runtime. Though you wont be able to access your views using R.id.whatever but you can always use visual tree to access the views or while parsing the views store the referenced objects to access them for later use.
Hope this gives you a starting point.

Copying android .apk to another .apk file through java code and over-ride its assets files?

is it possible to create .apk file by copying an already existing .apk file and modifying its assets folder? I have some information in a file in assets folder containing server ip and port to which the user is to connect. Users are from different regions and have to connect through different servers. can anyone tell me how to implement this?
I've added a comment with my recommended solution to this problem. However, here's an answer to your question:
Of course you can unpack the APK, swap out the assets and then create a new APK from that. However, you will need to sign the APK again with the correct key.
If you are building the apps yourself, you can just build multiple APKs, each containing a different asset file. However, you would have to distribute these APKs by hand (ie: they can't be uploaded to Google Play) because they would each have the same package name and you cannot have multiple apps in the app store with the same package name.

distribute Java classes and res folder separately

I have developed an android application, which uses image files and strings from the res folder. Is it possible for me to distribute the app in a manner that enables the users to modify the strings and images stored in the res folder, without accessing the code from the java classes.
Can I distribute these separately, so that a user can modify the value of the strings and replace the images (not add new or delete existing) and rebuild the apk, without being able to read the Java code?
Thanks.
Ani
I think your best bet would be to build a web interface where users can upload the images and strings they want into a form, you can generate the resources on the server, package it up and sign it, then give them back a download link.
The whole process could be automated as long as you have Java and headless aapt installed on the server.
http://developer.android.com/guide/developing/building/index.html#detailed-build

Choosing the right data storage alternative

I'm coding an android app for parsing sms messages. I need different rules for different countries and idea is to define rules for my country and later open source project so other users can contribute with rules for their countries. XML format is the most convenient in my opinion for defining these rules.
So I have an app which reeds rules from XML file stored in res/raw and users will later be able to update that set of rules or download rules for some other country when those become available.
As I said I have put existing XML files in res/raw, but the problem is when users download new or changed set of rules application can not change or store files in resources (correct me if I'm wrong).
So I have two options now, and I don't like either one. I would like to hear your opinions on the matter.
a) I can keep XML files as local files, but then I must read in default rules from res/raw and copy them into file system on application installation, or keep track of two separate bunch of files. Is it possible to preinclude files on file system when installing an app?
b) I can keep XML code in database, but also copy it from files at install time. Or even worse code XML as String in class to insert it on install?
I apologize if question is too long or unclear, English is not my native language and this is my first question.
I'm not sure if i understood you right, but you could store the XML-file in the internal data storage of the application. --> http://developer.android.com/guide/topics/data/data-storage.html
If you want to attach a first Version of the XML-file on install, store it in the ressources first and copy it to the internal data storage after install. On updates of the XML file you can just overwrite this file in the internal data storage.
Hope i could help you, this is my first answer on stackoverflow. I'm sorry if i just told you things you already knew.

Categories

Resources