Networking with the Fast Android Networking Library
About Fast Android Networking Library
Fast Android Networking is a third-party library that wraps OkHttp with fluent builders for GET/POST, file upload/download, image loading, and JSON parsing.
Historical reference — prefer a modern, Kotlin-first stack for new code. The library’s last source-code release was v1.0.2 on 2018-07-10; the 1.0.3 and 1.0.4 tags published on 2024-08-18 bundle only Gradle/JitPack republishing changes — a
git compareshows zero files underandroid-networking/src/changed across the six-year gap. Every API on this page is a Java SAM-interface callback (JSONObjectRequestListener,DownloadListener, etc.) — there is no Kotlin or coroutine source in the repository, so the snippets below cannot be translated into idiomaticsuspend-function form without reverting to the same callback shape. For new networking work on Android, prefer:
- Retrofit with
suspendfunctions — native coroutine support since Retrofit 2.6.0 on 2019-06-05; current stable 3.0.0. See Consuming APIs with Retrofit.- OkHttp directly + coroutines — the optional
okhttp-coroutinesartifact ships with OkHttp 5.x. See Using OkHttp.- Ktor Client — JetBrains’ Kotlin-first HTTP client, current stable 3.5.0 (2026-05-18). Designed around coroutines and multiplatform from the start.
The remainder of this page is preserved as a reference for codebases that still depend on Fast Android Networking. Some snippets use
try { ... } catch (JSONException e) { e.printStackTrace(); }— that pattern is illustrative of upstream sample code, not a recommended error-handling style; log viaLog.e(...)or surface the failure to the caller in real code.
Requirements
The 1.0.4 module declares minSdkVersion 14 (Android 4.0, Ice Cream Sandwich) and compileSdkVersion 27 — see the pinned ext block in the root build.gradle at tag 1.0.4, unchanged since v1.0.2. Apps consuming it today are still bound by their own minSdkVersion and compileSdk.
Historical reference: using Fast Android Networking Library in your application
The library is distributed via JitPack. Add the JitPack repository to your top-level settings.gradle (or build.gradle if you still configure repositories there):
dependencyResolutionManagement {
repositories {
google()
mavenCentral()
maven { url 'https://jitpack.io' }
}
}
Then add this in your module’s build.gradle:
implementation 'com.github.amitshekhariitbhu.Fast-Android-Networking:android-networking:1.0.4'
Note: the older
com.amitshekhar.android:android-networkingartifact on Maven Central / JCenter has not been updated past1.0.2. The 1.0.4 release is only published through JitPack with thecom.github.amitshekhariitbhu.*coordinates above. See the upstream README.
For RxJava2 Support, check here.
Do not forget to add internet permission in manifest if already not present
<uses-permission android:name="android.permission.INTERNET" />
Then initialize it in onCreate() Method of application class :
AndroidNetworking.initialize(getApplicationContext());
Making a GET Request
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
}
});
Making a POST Request
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
}
});
You can also post java object, json, file, etc in POST request like this.
User user = new User();
user.firstname = "Amit";
user.lastname = "Shekhar";
AndroidNetworking.post("https://fierce-cove-29863.herokuapp.com/createUser")
.addBodyParameter(user) // posting java object
.setTag("test")
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
// do anything with response
}
@Override
public void onError(ANError error) {
// handle error
}
});
JSONObject jsonObject = new JSONObject();
try {
jsonObject.put("firstname", "Rohit");
jsonObject.put("lastname", "Kumar");
} catch (JSONException e) {
e.printStackTrace();
}
AndroidNetworking.post("https://fierce-cove-29863.herokuapp.com/createUser")
.addJSONObjectBody(jsonObject) // posting json
.setTag("test")
.setPriority(Priority.MEDIUM)
.build()
.getAsJSONArray(new JSONArrayRequestListener() {
@Override
public void onResponse(JSONArray response) {
// do anything with response
}
@Override
public void onError(ANError error) {
// handle error
}
});
AndroidNetworking.post("https://fierce-cove-29863.herokuapp.com/postFile")
.addFileBody(file) // posting any type of file
.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
}
});
Using it with your own JAVA Object - JSON Parser
/*--------------Example One -> Getting the userList----------------*/
AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}")
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.setTag(this)
.setPriority(Priority.LOW)
.build()
.getAsObjectList(User.class, new ParsedRequestListener<List<User>>() {
@Override
public void onResponse(List<User> users) {
// do anything with response
Log.d(TAG, "userList size : " + users.size());
for (User user : users) {
Log.d(TAG, "id : " + user.id);
Log.d(TAG, "firstname : " + user.firstname);
Log.d(TAG, "lastname : " + user.lastname);
}
}
@Override
public void onError(ANError anError) {
// handle error
}
});
/*--------------Example Two -> Getting an user----------------*/
AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAnUserDetail/{userId}")
.addPathParameter("userId", "1")
.setTag(this)
.setPriority(Priority.LOW)
.build()
.getAsObject(User.class, new ParsedRequestListener<User>() {
@Override
public void onResponse(User user) {
// do anything with response
Log.d(TAG, "id : " + user.id);
Log.d(TAG, "firstname : " + user.firstname);
Log.d(TAG, "lastname : " + user.lastname);
}
@Override
public void onError(ANError anError) {
// handle error
}
});
/*-- Note : YourObject.class, getAsObject and getAsObjectList are important here --*/
Downloading a file from server
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
}
});
Uploading a file to server
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
}
});
Getting Response and completion in an another thread executor
(Note : Error and Progress will always be returned in main thread of application)
AndroidNetworking.upload(url)
.addMultipartFile("image",file)
.addMultipartParameter("key","value")
.setTag("uploadTest")
.setPriority(Priority.HIGH)
.build()
.setExecutor(Executors.newSingleThreadExecutor()) // setting an executor to get response or completion on that executor thread
.setUploadProgressListener(new UploadProgressListener() {
@Override
public void onProgress(long bytesUploaded, long totalBytes) {
// do anything with progress
}
})
.getAsJSONObject(new JSONObjectRequestListener() {
@Override
public void onResponse(JSONObject response) {
// below code will be executed in the executor provided
// do anything with response
}
@Override
public void onError(ANError error) {
// handle error
}
});
Getting Bitmap from URL with some specified parameters
AndroidNetworking.get(imageUrl)
.setTag("imageRequestTag")
.setPriority(Priority.MEDIUM)
.setBitmapMaxHeight(100)
.setBitmapMaxWidth(100)
.setBitmapConfig(Bitmap.Config.ARGB_8888)
.build()
.getAsBitmap(new BitmapRequestListener() {
@Override
public void onResponse(Bitmap bitmap) {
// do anything with bitmap
}
@Override
public void onError(ANError error) {
// handle error
}
});
Error Code Handling
public void onError(ANError error) {
if (error.getErrorCode() != 0) {
// received error from server
// error.getErrorCode() - the error code from server
// error.getErrorBody() - the error body from server
// error.getErrorDetail() - just an error detail
Log.d(TAG, "onError errorCode : " + error.getErrorCode());
Log.d(TAG, "onError errorBody : " + error.getErrorBody());
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
// get parsed error object (If ApiError is your class)
ApiError apiError = error.getErrorAsObject(ApiError.class);
} else {
// error.getErrorDetail() : connectionError, parseError, requestCancelledError
Log.d(TAG, "onError errorDetail : " + error.getErrorDetail());
}
}