Fast Android Networking Library - With Examples


Fast Android Networking Library Tutorial and Examples.

Fast Android Networking Library is a Complete Android Networking Library that also supports HTTP/2 created by Amit Shekhar, a popular open source contributor.

It provides us with powerful networking capabilities yet in an elegant manner. It's a mature library and is currently one of the most popular networking library.

Fast Android Networking Library allows us perform any type of networking in Android applications.

It's a library built on top of OkHttp Networking Layer.

Fast Android Networking Library does alot of work for you in the background, such that you only make your request and listen for the response.

Top Reasons to start using Fast Android Networking ?

Here are some of the reasons why you need to consider using this library for networking needs in android.

  1. Android Framework Engineers in the recent years got rid of HttpClient, that is in Android Marshmallow(Android M). Because of this alot of networking libraries like Volley became obsolete.
  2. Fast Android Networking does allows you do these things easier than any other library:

    1. Making HTTP requests.
    2. Downloading any type of file.
    3. Uploading files.
    4. Loading image from network into ImageView, etc.
  3. Fast Networking Library provides a simple interface for doing all types of things in networking like setting priority, cancelling, etc.
  4. Fast Networking Library uses Okio hence no more GC overhead in android applications. Okio is made to handle GC overhead while allocating memory. Okio does some clever things to save CPU and memory.
  5. Fast Networking Library is built on top of the proven OkHttp.
  6. Fast Networking Libary supports HTTP/2.

Requirements

Fast Android Networking Library is generous with it's requirements.

To use it you need:

  1. Android 2.3 (Gingerbread) and later.

Fast Networking Libary Installation

To insall Fast Networking Library, head over to your app level and add it as a dependency:

implementation 'com.amitshekhar.android:android-networking:1.0.2'

Then in your android manifest don't forget to add permission:

<uses-permission android:name="android.permission.INTERNET" />

Using it in Java

Well once you've installed it you can head over to your java code and initialize it first:

AndroidNetworking.initialize(getApplicationContext());
1. How to make a HTTP GET Request in Fast Networking Library

You invoke the AndroidNetworking.get() method:

AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}")
                 .addPathParameter("pageNumber", "0")
                 .addQueryParameter("limit", "3")
                 .addHeaders("token", "1234")
                 .setTag("test")
                 .setPriority(Priority.LOW)
                 .build()
                 .getAsJSONArray(new JSONArrayRequestListener() {
                    @Override
                    public void onResponse(JSONArray response) {
                      // do anything with response
                    }
                    @Override
                    public void onError(ANError error) {
                      // handle error
                    }
                });  
2. How to make a HTTP PSOT Request in Fast Networking Library

You invoke the AndroidNetworking.post() method:

AndroidNetworking.post("https://fierce-cove-29863.herokuapp.com/createAnUser")
                 .addBodyParameter("firstname", "Amit")
                 .addBodyParameter("lastname", "Shekhar")
                 .setTag("test")
                 .setPriority(Priority.MEDIUM)
                 .build()
                 .getAsJSONObject(new JSONObjectRequestListener() {
                    @Override
                    public void onResponse(JSONObject response) {
                      // do anything with response
                    }
                    @Override
                    public void onError(ANError error) {
                      // handle error
                    }
                });
3. How to Download a File in Fast Networking Library

You invoke the AndroidNetworking.download() method:

AndroidNetworking.download(url,dirPath,fileName)
                 .setTag("downloadTest")
                 .setPriority(Priority.MEDIUM)
                 .build()
                 .setDownloadProgressListener(new DownloadProgressListener() {
                    @Override
                    public void onProgress(long bytesDownloaded, long totalBytes) {
                      // do anything with progress  
                    }
                 })
                 .startDownload(new DownloadListener() {
                    @Override
                    public void onDownloadComplete() {
                      // do anything after completion
                    }
                    @Override
                    public void onError(ANError error) {
                      // handle error    
                    }
                });  
4. How to Upload a File to Server in Fast Networking Library

You invoke the AndroidNetworking.upload() method:

AndroidNetworking.upload(url)
                 .addMultipartFile("image",file)    
                 .addMultipartParameter("key","value")
                 .setTag("uploadTest")
                 .setPriority(Priority.HIGH)
                 .build()
                 .setUploadProgressListener(new UploadProgressListener() {
                    @Override
                    public void onProgress(long bytesUploaded, long totalBytes) {
                      // do anything with progress 
                    }
                 })
                 .getAsJSONObject(new JSONObjectRequestListener() {
                    @Override
                    public void onResponse(JSONObject response) {
                      // do anything with response                
                    }
                    @Override
                    public void onError(ANError error) {
                      // handle error 
                    }
                 }); 

Top Android HTTP Examples

Let's look at some examples.

Android Fast Networking Library JSON Examples.

Android Fast Networking Library MySQL Database Examples.

MySQL is our database while PHP is the server side language we use. The client code is for android is written in this case in either Java or Kotlin.

Best Regards, Oclemy.

How do You Feel after reading this?

According to scientists, we humans have 8 primary innate emotions: joy, acceptance, fear, surprise, sadness, disgust, anger, and anticipation. Feel free to tell us how you feel about this article using these emotes or via the comment section. This feedback helps us gauge our progress.

Help me Grow.

I set myself some growth ambitions I desire to achieve by this year's end regarding this website and my youtube channel. Am halfway. Help me reach them by:




Recommendations


What do You Think


Previous Post Next Post