How to fetch xml from web services and save it in assets - android

I am developing an android app and in that I want to use a XML file. I think its a kinda web services and i want to use it in my app. so first of all i am thinking that whenever I open my app it fetch the whole XML file from http://data.gov.in/sites/default/files/Date-Wise-Prices-all-Commodity.xml and save it into assets folder of my App and then after I will use this XML from my assets folder.
I know this stuff is not too much difficult but actually i am new to android that's why getting this type of problem.
Please help.
Thanks in Advance.

You can't. The assets folder is read-only at runtime.
Pick a different location to save your data, see Data Storage for more information.

As posted in other answer you have to choose different location.
Rest method is as following.
Make a method or class to make http request.
Get response from given request.
Make a xml parser (DOM Parser,Pull Parser or SAX)
these are the basic steps. hope it will help.
Check this tutorial

Related

How to prevent the sensitive data used by app in android?

As we all know Android app apk file can be drilled down to get the Java codes and resources. The sensitive data used to populate lets say list view used as arrays in Java files can be easily hacked.
What are the secure ways to do it?
I guess downloading XML or JSON file from the internet and using in app? Or there any other techniques?
Thanks in advance.

Android read / access online xml file

I make a android application themed puzzles,
and the answers I put in the xml file,
in folder assets/file.xml, I add also proguard.
after I publish it on google play,
The application turns in reverse engineering by someone,
so that all the answers are there in the xml file unreadable
and distributed on the Internet.
I plan to move this xml file online
eg I put in www.example.com/folder/file.xml to make it more secure.
My question, how to read / access the online xml file?
thanks.
One method i hvae used is use of webservice to make requests and get xml response. I have achieved this using Soap webservice, i make soap request from my app, and get xml response from server then i can parse the results. This means that you will be storing your answers dynamically in your database, so no one can tamper with them unless they hack database. It is also advisable to use dynamic puzzle question, i.e, store the puzzle questions in an online database so that you can update them without having to go back and update code in the app.

Using an online .txt file as a data source

I am building an Android app for a client and most of the data that i need is contained in an online .txt file attached to my clients website. I've never used an online .txt file as a data source before and don't really know where to begin?! Can anyone point me in the direction of a good tutorial on the subject.
Many Thanks in advance
P.S. I haven't asked whether it's possible because i have assumed it is due to the fact you can use an internal .txt file as a data source
I think the best approach is to download the file on the device and then read it like a normal file. If the file changes on a period of time, then configure the app to download and read the file and then update the local info in the app.
I don't think you can use an online txt as a DataSource, but you can implement this so you have an abstract source for your file, and then just call read on it.
Expose the txt/xml file over web,if you want to get it down to phone use URL loader and load it to the phone and operate if you want to use it online (like others may also be using it) it will be a bit complex in order to deal with data coming from more then one source but possible. clear you question a bit more.

Storing data and files

I am porting an application originally written for WP7 and just need to know how to do something under Mono for Android which I could do on WP7 using IsolatedStorage.
For simple key/value data such as the username and password used to login I am using SharedPreferences and I think that this will work fine, however I read an XML file from a web service and need to be able to store this file locally, be able to update its contents and ultimately upload it back to the web server.
Under WP7 the code would serialize the XML and then save this to application settings - I guess I can do something very similar in Android but the question is this the best way to store an XML data file?
Thanks
You can do almost the same thing as you would on the WP, as the same .net libraries for xml and serialization should be available on Mono for Android.
You can then also save it to isolated storage or wherever you like.
You can use one of the common java libraries to work with XML, such as JDOM or SAX. You can then write this to android storage as per Maxim's comment link above.
You can write the XML as a string to a file in the Internal Storage or the SD Card. Check the Developer Documentation for more information: http://developer.android.com/guide/topics/data/data-storage.html

How to load an SQL query from an XML file on Android?

For the Android app that I'm working on I have to do some lengthly sqlite queries, and it was making my code hard to follow. Is there any way I can put the queries into an XML file and then load them from there?
I'm attempting to do something similar to this.
You could create an XML file like the one you linked to under the res/xml/ directory, or use the res/raw/ directory and store it in some other format of your choosing. Then read the resource in as you normally would with Android, parse it if necessary, and interact with your database directly by using SQLiteDatabase.execSQL.
For specifics, it really depends on your needs and application architecture.

Categories

Resources