Interacting with the server API from android application - android

Can anyone explain for me or guide me through the basics that i have to know on how to interact with the server API from Android Application?
Any good website that teaches beginners because am new to this thing and am quite lost

If it is a restful API that you will be interacting with, I would highly recommend using RetroFit.
http://square.github.io/retrofit/
Square have excellent documentation and the examples should be easy to follow. If you get stuck you can always post on here under the Retrofit tag which has a fairly large following.
Volley is also an option.

Use Volley networking library http://developer.android.com/training/volley/index.html

This example shows how to make simple client-server app right now.
Here and here you can read description during making client-server app.
I found those links very useful for me when I started to learn this topic.
Hope it helps.

To get you started I've have a sample app Link which uses Github's REST and fetch the result and display it in android List. It is a basic one without any authentication. Hope this helps.

Recently android has introduced a library to parse json. It is called volley.
Volley offers the following benefits:
Automatic scheduling of network requests.
Multiple concurrent network connections.
Transparent disk and memory response caching with standard HTTP cache
coherence.
Support for request prioritization.
Cancellation request API. You can cancel a single request, or you can
set blocks or scopes of requests to cancel.
Ease of customization, for example, for retry and backoff.
Strong ordering that makes it easy to correctly populate your UI with
data fetched asynchronously from the network.
Debugging and tracing tools.
Tutorial which I used is Volley tutorial for json parsing. Another link is here
Hope this helps you.

Related

Easy android https request?

I know, there are much posts and answers on this topic and it seems, I have read them all... But I just want to know how to do an easy https request in my Android app. Is there a easy class which make such an request?
I want to call something like
String response = new EasyHttpRequest().execute(myUrl).get();
in my MainActivity
For information I can't just set the response Text to an TextView in the onPostExecute() method, I have to work with this data and save it or something else.
The best library I know so far for network requests is Retrofit. It's kind of a standard for Android apps. If you want something more low level you can use Okhttp.
Both libraries can work together, and they are more than production ready. Of course, they support https and many other security features as ssl certificate pinning.
They support running the request on the same thread you are or in a background queue provided by the library, up to you if then you want to wrap it on an asyncTask, simple thread or service, those libraries leave you some freedom in that matter.
You can use this repo . it's very easy to use.
okhttp-utils

RESTful Client Verses normal HTTP Client For Android?

I am developing an Android App. I read about RESTful Webservices and decided to use that for my app. But I have doubt about REST Client
After reading many article I understood that
I can directly write code to make HTTP request from android
App as given in Connenting To Network OR
I can write code to develop the RESTful client OR
I can use some already developed Third Party lib like RESTDroid
I am not able to decide should directly write code to make the HTTP request as suggested by developers guide or i should follow the rest client model.
What is the advantage of using rest client over directly making HTTP request ( or can say using non-RESTful Client) ?
I am new to android and REST architecture. Please correct me if I am wrong.
This is quite a broad answer but I will divide it in 2 parts:
1) Rest and non-Rest clients:
In my experience I have not seen any REST client except the browsers
the industry trimmed part of the original REST specification and created improved HTTP clients/services and called them REST which(most of them) are not different than any ordinary HTTP library.
So for Android you will get ordinary HTTP Clients with various features but the REST part you will need to code it yourself.
2) What is better to use
Clearly I would not advise to write your own HTTP client as it is far from trivial job to do.
I would not advise to use Retrofit for a really RESTful service as it is not good for that. You better build something on top of OkHttp or extend Volley or Jus which is my creation and it will support basic HATEOAS implementations from version 0.7.0 and optimized pipeline and memory utilization from version 1.0.0 (follow it on github :)

How does android retrieve data from a website?

I'm new to android, I'm trying to build an android app that is a front for a web portal. For example, Airbnb. They have a website, but they also have an android app that, using it's own layout, will show listings from their website.
There are many websites that teach how to or even directly convert your website to android apps. However, this will result in an app that loads too slowly and is unresponsive due to CPU usage.
Could anyone share any tutorial/guide to learn how to do this myself?
Million thanks.
To actually load data from a web server you're gonna need and API which usually delivers the proper date using JSON or XML format so that you can properly parse and display that data. Building this API is in it self a complete course on its own.
But connecting to and requesting data from the API is usually done using some networking libraries. These are some of the better know libraries for this purpose.
OkHttp: A complete library with a set of tools for handling network connections and HTTP requests.
RetroFit:Type-safe HTTP client for Android and Java by Square, Inc. which is built on top of OkHttp.
Async-Http-Client:
The Async Http Client library's purpose is to allow Java applications
to easily execute HTTP requests and asynchronously process the HTTP
responses. The library also supports the WebSocket Protocol. The Async
HTTP Client library is simple to use.
There tons of other good libraries.
its called webservices
Through android you get data in form of json from a web server and then return in custom view as you want.
Follow this link hope it will help
Step by Step Method to Access Webservice from Android
you would have to write an API/Web service or use if already exits to fetch data from web server. Basically the concept is that, the website itself must be pulling data from some database, so write an API which would fetch the data from same API and return JSON data and consume the API from your android app.
If you know PHP refere to this for the help :http://www.codeproject.com/Articles/267023/Send-and-receive-json-between-android-and-php
You can write WebService, in programming it generally refers to a web page(ex. Airbnb), that can be called from your android application which can pass in data to it, or receive data from it.
WebService is basically like a 'method' or 'function' in a normal programming language; except you're calling it over the internet.
The first thing is you have to create a Web Service. The Web Service will be your "bridge" to consume the data from other Website like airbnb or others and return the data to your android through json format for example.
You can create a Web Service using many languages like C#, Java, PHP, etc. I would like to recommend you to use the language that you know the most.
You can try to google this
Cheers

Does the time in which response is received in Android from the web service depends on the library that we use for httpconnection?

This may be a very basic question. But please clear a doubt that I have. Does the time in which response is received in Android App from the web service depends on the library we use for http connection? I mean is some library give faster response than others?
Thanks
Use Volley library that is recommended by Google.
Here is nice example of caching your response. How to use this
http://www.androidhive.info/2014/05/android-working-with-volley-library-1/

Is an Android Service a good idea when backing up an app's data using a web service?

I'd like to add the ability for my android app to save changes to data (stored in its SQLite database) to a web server. The upload will be via HTTP POST, using JSON in the body of the request to describe the changes.
I'm wondering if I should use an android Service for this. I'd like the user to be able to continue interacting with the app while it's generating the JSON, making the call to the server, and waiting for the server to complete its work and return a response.
Thanks much!
Even better would be an IntentService
Edit: Now that the compatibility package is out I think the new Loader class may be the best option, possibly using the ASyncTask version or a variation of it.
Yes it is a very good idea to move all the webservice code into a service. The Google IO talk Developing Android REST client applications talks about many reasons why this is a good idea. It also covers other important considerations which relate to your problem which is effectively syncing your database to the cloud.

Categories

Resources