I want to send data to the server using asp web service from my Android application. For this I'm using ksoap2 library. The data I'm sending is in the form of an Content object. The structure of Content class is:
class Content{
int contentId;
string xmlContent;
}
The xmlContent is big, 1k to 100k lines. My question is, using ksoap2 library is recommended for this type of operations? Is there any limitations of ksoap2 library?
I have also used the Ksop in my program.But i never faced such difficulty it can't be overcome. I have one suggestion to you to use JSON rather than xmlContent. There is a inbuilt java serialization in asp. Just use that and you will get a json response inside you android.Just parse the json using ksop. Here you will get a good idea about ksop.
Related
I am trying to send a simple JSON payload via a websocket in android.
I did it in python like this:
self.connection = websocket.create_connection(url, config["timeout"])
self.connection.send(payload)
and that's it.
but in JAVA it's all way too complicated and I saw in some places that I need to use okhttp3 sockets, other places I saw that I need to convert it into bytes.. and I'm not sure on how to aproach it with JAVA for android.
I need to get some simple data (actual currency values) to my android application. I'm not sure what is the best way to achieve it. Do I have to make some database and put it on server and than update it manually or there is some better way?
You can use an API Service and access to this service from you android device. You donot need to do a server implementation for this.
e.g. for exchange rates check https://openexchangerates.org/
Yes.
Please make a server and a PHP which going to print out the values in JSON. You can validate your json with http://jsonlint.com/. After it you can download and parse the json with yourself or a 3rd part library (like retrofit).
You can use this website to generate POJO, so retrofit can parse the json for you by it`s own.
http://www.jsonschema2pojo.org/
select: JSON instead of scheme and select GSON instead of JSON, if you are using retrofit.
sources:
https://en.wikipedia.org/wiki/Gson
https://github.com/square/retrofit
http://blog.robinchutaux.com/blog/a-smart-way-to-use-retrofit/
I need to retrieve huge amounts of data from a database through a web service from an Android app. I have two different ways to do this, and I wanted some advice on it:
1. The first option is to create a .php file on the server side that managed any POST coming from the client (Android app). The server would then create a JSON response. Finally we would parse this response using a JSON parser in Android. This is also known as the REST scheme.
2. The second option is to create a SERVLET, execute it from the client (Android), have the servlet send the request to the database for us, and finally parse that data from Android. Obviously the servlet would be written so that it could easily interact with the database.
Points to note (so as to decide which option is better):
1. I won't be storing anything in the database from the client. That is, my Android app is read-only.
2. I will be reading from a huge database, so it is a priority here the performance of the Client-Server interaction, with a special mention for data parsing and for servlet vs php performance.
Any help would be greatly appreciated.
Android has built-in support for parsing JSON data with the use of JSONObjects and JSONArrays, so it would be a lot easier to handle data in that form, rather than handling servlets. Its even possible to directly receive the web service response as a JSONObject or JSONArray.
In general, web services in Android should be of the RESTful type. That's how Google seems to prefer it. That's why there's built-in support for JSON, but not for SOA or Servlets.
References:
1. Reasons for not directly write Servlets for creating a REST API.
2. Servlet vs REST.
I just started using the website http://www.kimonolabs.com and created an API as I need to retrieve data from my school website to put into the school app I am creating. Unfortunately, I do not really plan ahead, and this leads me to my 2 questions:
1) How do I include this API in my school Android App?
2) How do I parse the JSON in this API? (Or just linking me to another page on this would be equally as greatly appreciated :) )
Thanks very much for any help you can give! Sorry for my language, I am 14 :P
First things first. Take a look at AsyncTask in Android. AsyncTask is used to perform operations asynchronously. Take a look at this answer explaining how parameters are passed to AsyncTask.
You can use libraries mentioned bellow to do same thing:
Asynchronous Http Client
Volley
Once you communicate with server and receive response, you have to parse JSON data.
The key you have to remember for this is
[] - square bracket represents JSON Array
{} - curly bracket represents JSON Object
Everything else will be combination of these.
This tutorial will help you regarding JSON parsing.
JSON object to Java object conversion
To convert json data to java object you can use:
Jackson
Gson
Follow this link or this link for nice GSON tutorial.
I personally used GSON, and it is best library for json to java object conversion.
I have a .net webApi project that contains some methods.
The methods send and get complex objects.
My android application gets the objects in json format and parsing them manually.
In any changes of the objects in the WebApi project I have to change manually the android application project.
I would like to know what is the best practice to work with android application client and .Net WebApi.
There is any tool to connect between them or to auto map the objects?
Please help me
Tal
U do use json parsing technique for parsing the json responses.its proper way of data parsing there is i think no tool for auto mapping.
From the Android Client end you have to use Spring RestTemplate together with Data Transfer Objects (DTOs). You wouldn't need to manually manipulate a JSON String values. It's all about dealing with Java Objects then. You can directly pass the Objects to the RestTemplate as Entity classes and get the JSON String Auto Mapped to your DTOs.