A Complete Fast Android Networking Library that also supports HTTP/2
A Complete Fast Android Networking Library that also supports HTTP/2
Fast Android Networking Library is a powerful library for doing any type of networking in Android applications which is made on top of OkHttp Networking Layer.
Fast Android Networking Library takes care of each and everything. So you don't have to do anything, just make request and listen for the response.
Hi, I am Amit Shekhar, Founder @ Outcome School • IIT 2010-14 • I have taught and mentored many developers, and their efforts landed them high-paying tech jobs, helped many tech companies in solving their unique problems, and created many open-source libraries being used by top companies. I am passionate about sharing knowledge through open-source, blogs, and videos.
Join Outcome School and get a high-paying tech job: Outcome School
For full details, visit the documentation on our web site :
Fast Android Networking Library can be included in any Android application.
Fast Android Networking Library supports Android 2.3 (Gingerbread) and later.
Add this in your settings.gradle:
maven { url 'https://jitpack.io' }
If you are using settings.gradle.kts, add the following:
maven { setUrl("https://jitpack.io") }
Add this in your build.gradle
implementation 'com.github.amitshekhariitbhu.Fast-Android-Networking:android-networking:1.0.4'
If you are using build.gradle.kts, add the following:
implementation("com.github.amitshekhariitbhu.Fast-Android-Networking:android-networking:1.0.4")
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());
Initializing it with some customization , as it uses OkHttp as networking layer, you can pass custom okHttpClient while initializing it.
// Adding an Network Interceptor for Debugging purpose :
OkHttpClient okHttpClient = new OkHttpClient() .newBuilder()
.addNetworkInterceptor(new StethoInterceptor())
.build();
AndroidNetworking.initialize(getApplicationContext(),okHttpClient);
Using the Fast Android Networking with Jackson Parser
Add this in your build.gradle
implementation 'com.github.amitshekhariitbhu.Fast-Android-Networking:jackson-android-networking:1.0.4'
If you are using build.gradle.kts, add the following:
implementation("com.github.amitshekhariitbhu.Fast-Android-Networking:jackson-android-networking:1.0.4")
// Then set the JacksonParserFactory like below
AndroidNetworking.setParserFactory(new JacksonParserFactory());
Using the Fast Android Networking with RxJava2
Add this in your build.gradle
implementation 'com.github.amitshekhariitbhu.Fast-Android-Networking:rx2-android-networking:1.0.4'
If you are using build.gradle.kts, add the following:
implementation("com.github.amitshekhariitbhu.Fast-Android-Networking:rx2-android-networking:1.0.4")
Using the Fast Android Networking with RxJava
Add this in your build.gradle
implementation 'com.github.amitshekhariitbhu.Fast-Android-Networking:rx-android-networking:1.0.4'
If you are using build.gradle.kts, add the following:
implementation("com.github.amitshekhariitbhu.Fast-Android-Networking:rx-android-networking:1.0.4")
…
…
You can also post java object, json, file, etc in POST request like this.
…
…
…
…
(Note : Error and Progress will always be returned in main thread of application)
…
…
Any request with a given tag can be cancelled. Just do like this.
AndroidNetworking.cancel("tag"); // All the requests with the given tag will be cancelled.
AndroidNetworking.forceCancel("tag"); // All the requests with the given tag will be cancelled , even if any percent threshold is
// set , it will be cancelled forcefully.
AndroidNetworking.cancelAll(); // All the requests will be cancelled.
AndroidNetworking.forceCancelAll(); // All the requests will be cancelled , even if any percent threshold is
// set , it will be cancelled forcefully.
<com.androidnetworking.widget.ANImageView
android:id="@+id/imageView"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="center" />
imageView.setDefaultImageResId(R.drawable.default);
imageView.setErrorImageResId(R.drawable.error);
imageView.setImageUrl(imageUrl);
…
…
AndroidNetworking.evictBitmap(key); // remove a bitmap with key from LruCache
AndroidNetworking.evictAllBitmap(); // clear LruCache
AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}")
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "30")
.setTag(this)
.setPriority(Priority.LOW)
.build()
.prefetch();
…
…
…
…
…
ANRequest request = AndroidNetworking.get("https://fierce-cove-29863.herokuapp.com/getAllUsers/{pageNumber}")
.addPathParameter("pageNumber", "0")
.addQueryParameter("limit", "3")
.build();
ANResponse<List<User>> response = request.executeForObjectList(User.class);
if (response.isSuccess()) {
List<User> users = responseTwo.getResult();
} else {
//handle error
}
AndroidNetworking.enableLogging(); // simply enable logging
AndroidNetworking.enableLogging(LEVEL.HEADERS); // enabling logging with level
// Enabling GZIP for Request (Not needed if your server doesn't support GZIP Compression), anyway responses
// from server are automatically unGzipped if required. So enable it only if you need your request to be
// Gzipped before sending to server(Make sure your server support GZIP Compression).
OkHttpClient okHttpClient = new OkHttpClient().newBuilder()
.addInterceptor(new GzipRequestInterceptor())
.build();
AndroidNetworking.initialize(getApplicationContext(),okHttpClient);
Use IMMEDIATE Priority with caution - use is at appropriate place only when 1 or 2 (at max 2)IMMEDIATE request is required at instant.Otherwise use HIGH Priority.
Known Bug : As present if you are using GZIP Interceptor from client to server, Upload progress is not working perfectly in Multipart.
If you are using Proguard with Gradle build system (which is usually the case), you don't have to do anything. The appropriate Proguard rules will be automatically applied. If you still need the rules applied in proguard-rules.pro, it is as follows:
-dontwarn okio.**
As it uses OkHttp as a networking layer, it supports:
No open issues yet, or sync has not completed.