Source link:

#NetworkUtils An Android Library for common network operations with a fluent and easy to use API.

Simple, fast and thread safe library that extends the existing Android Network-API and adds more features to it.

##Table of Contents

  1. Sample Application
  2. Gradle Dependency
    1. Repository
    2. Dependency
  3. Library Features Overview
    1. General Overview
    2. NetworkUtils Javadoc
  4. Installation
  5. Synchroneous Calls
  6. Asynchroneous Calls
  7. ToDo List
  8. About & Contact
  9. License

Sample Application

Please check the sample repository for a live-preview on how to use this library (of course this is only one of a few possibillities). You can download the sample apk directly from this repository

Gradle Dependency


NetworkUtils is a Free and OpenSource Android Library which can be found on GitHub.

The binary packages of this library are published on Maven Central and can be included into your project by only adding the library as dependency to your project.

Please make sure you're always using the latest version of NetworkUtils


Note: NetworkUtils uses Semantic Versioning for it's release/snapshot version number naming.

To use this library, all you have to do is to include it into your project's build.gradle file:

dependencies {

//other dependencies here...

compile 'com.pddstudio:networkutils:x.y.z'
//make sure you're always using the latest version of NetworkUtils 

Library Features Overview

Down below you can find a list of all current features the library comes with.

General Overview

  • Simple Network Utilities (like getting the current IP-Address, and more...)
  • ARP (Address Resolution Protocol) resolver and IP- / Mac-Address Mapper
  • AdBlock detection (based on the phone's host file)
  • Ping Utilities for checking local/remote address availability using Android's native ping binary
  • Port Scanning Utilities for local/remote address scanning and open port detection (yet, supports TCP connections only)
  • Discovery Utilities for DNS based service discovery on a local network over Multicast DNS (Avahi, Bonjour, ZeroConf)

NetworkUtils Javadoc

You can find the latest version of NetworkUtil's Javadoc here


Adding Permissions to your Application

After adding the library as dependency to your project, continue by preparing your application and adding the required permissions to your AndroidManifest.xml:

 <!-- This permission is required to perform network requests -->
  <uses-permission android:name="android.permission.INTERNET" />
  <!-- These permissions are required when using Utilities like retrieving the current IP-Address, ... -->

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

Now you can start using NetworkUtils in two ways:

1. Creating a Singleton instance

Creating a Singleton instance allows you to only instantiate the Library once and access it's created instance from everywhere in your code.

To create the Singleton instance all you have to do is to call it's initSingleton(Context context) method before retrieving an instance. Therefore it's recommended to instantiate the Library in your Application's onCreate(Bundle savedInstanceState) method.

  protected void onCreate(Bundle savedInstanceState) {



Toolbar toolbar = (Toolbar) findViewById(;


//other stuff in your onCreate method...



Now you can retrieve the NetworkUtils Singleton from everywhere in your application's code by calling:

 private void someNetworkMethod() {

//retrieve the NetworkUtils Singleton

NetworkUtils networkUtils = NetworkUtils.get();

//now you can call any method in the library as usual

Log.d("NetworkUtils", "Current IP-Address: " + networkUtils.getCurrentIpAddress());


2. Always retrieve a new instance

In case you want to get a new instance of NetworkUtils everytime you want to operate with the library you can retrieve it by calling it's get(Context context, Boolean flag) method:

  protected void onCreate(final Bundle savedInstanceState) {



Toolbar toolbar = (Toolbar) findViewById(;


//other stuff in your onCreate method...

 NetworkUtils networkUtils = NetworkUtils.get(this, true);


That's it! Now you can continue with synchronous or asynchronous requests.

##Synchronous Operations Synchronous Operations are supposed to be called only on already existing background jobs, you won't be able to call a synchronous request in your application's UiThread.

##Asynchronous Operations Asynchronous Operations are supposed to be called from your application's UiThread. The Library will execute your request(s) in the background and notify you about changes via the interface you provide. Asynchronous operations do always require a callback as parameter.

##ToDo List

  • Add proper samples to the Readme instead of the sample application
  • Implement Service which listens for network connection changes

##About & Contact

##License Copyright 2016 Patrick J

Licensed under the Apache License, Version 2.0 (the "License");
 you may not use this file except in compliance with the License. You may obtain a copy of the License at  Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 


Prevent screen from turning off until your user is looking at the screen.

Monotweety is a simple Twitter Client just for tweeting from notification area.

It demonstrates reactive mvvm-like architecture and Conductor, an framework that allows building View-based Android applications.

Use one line to apply almost famous libraries of proguard configurations.

RxDownloader is an RxWrapped Download Manager.

Simple JUnit rule for overriding RxJava/RxAndroid schedulers during unit tests.

A MultiScreen-Support-Library for Android.


2D Engines   3D Engines   9-Patch   Action Bars   Activities   ADB   Advertisements   Analytics   Animations   ANR   AOP   API   APK   APT   Architecture   Audio   Autocomplete   Background Processing   Backward Compatibility   Badges   Bar Codes   Benchmarking   Bitmaps   Bluetooth   Blur Effects   Bread Crumbs   BRMS   Browser Extensions   Build Systems   Bundles   Buttons   Caching   Camera   Canvas   Cards   Carousels   Changelog   Checkboxes   Cloud Storages   Color Analysis   Color Pickers   Colors   Comet/Push   Compass Sensors   Conferences   Content Providers   Continuous Integration   Crash Reports   Credit Cards   Credits   CSV   Curl/Flip   Data Binding   Data Generators   Data Structures   Database   Database Browsers   Date &   Debugging   Decompilers   Deep Links   Dependency Injections   Design   Design Patterns   Dex   Dialogs   Distributed Computing   Distribution Platforms   Download Managers   Drawables   Emoji   Emulators   EPUB   Equalizers &   Event Buses   Exception Handling   Face Recognition   Feedback &   File System   File/Directory   Fingerprint   Floating Action   Fonts   Forms   Fragments   FRP   FSM   Functional Programming   Gamepads   Games   Geocaching   Gestures   GIF   Glow Pad   Gradle Plugins   Graphics   Grid Views   Highlighting   HTML   HTTP Mocking   Icons   IDE   IDE Plugins   Image Croppers   Image Loaders   Image Pickers   Image Processing   Image Views   Instrumentation   Intents   Job Schedulers   JSON   Keyboard   Kotlin   Layouts   Library Demos   List View   List Views   Localization   Location   Lock Patterns   Logcat   Logging   Mails   Maps   Markdown   Mathematics   Maven Plugins   MBaaS   Media   Menus   Messaging   MIME   Mobile Web   Native Image   Navigation   NDK   Networking   NFC   NoSQL   Number Pickers   OAuth   Object Mocking   OCR Engines   OpenGL   ORM   Other Pickers   Parallax List   Parcelables   Particle Systems   Password Inputs   PDF   Permissions   Physics Engines   Platforms   Plugin Frameworks   Preferences   Progress Indicators   ProGuard   Properties   Protocol Buffer   Pull To   Purchases   Push/Pull   QR Codes   Quick Return   Radio Buttons   Range Bars   Ratings   Recycler Views   Resources   REST   Ripple Effects   RSS   Screenshots   Scripting   Scroll Views   SDK   Search Inputs   Security   Sensors   Services   Showcase Views   Signatures   Sliding Panels   Snackbars   SOAP   Social Networks   Spannable   Spinners   Splash Screens   SSH   Static Analysis   Status Bars   Styling   SVG   System   Tags   Task Managers   TDD &   Template Engines   Testing   Testing Tools   Text Formatting   Text Views   Text Watchers   Text-to   Toasts   Toolkits For   Tools   Tooltips   Trainings   TV   Twitter   Updaters   USB   User Stories   Utils   Validation   Video   View Adapters   View Pagers   Views   Watch Face   Wearable Data   Wearables   Weather   Web Tools   Web Views   WebRTC   WebSockets   Wheel Widgets   Wi-Fi   Widgets   Windows   Wizards   XML   XMPP   YAML   ZIP Codes