NetworkUtils

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

License

License

Categories

Categories

Net
GroupId

GroupId

com.pddstudio
ArtifactId

ArtifactId

networkutils
Last Version

Last Version

1.0.2
Release Date

Release Date

Type

Type

aar
Description

Description

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

Project URL

https://github.com/pddstudio/networkutils
Source Code Management

Source Code Management

https://github.com/pddstudio/networkutils

Download networkutils

How to add to project

<!-- https://jarcasting.com/artifacts/com.pddstudio/networkutils/ -->
<dependency>
    <groupId>com.pddstudio</groupId>
    <artifactId>networkutils</artifactId>
    <version>1.0.2</version>
    <type>aar</type>
</dependency>
// https://jarcasting.com/artifacts/com.pddstudio/networkutils/
implementation 'com.pddstudio:networkutils:1.0.2'
// https://jarcasting.com/artifacts/com.pddstudio/networkutils/
implementation ("com.pddstudio:networkutils:1.0.2")
'com.pddstudio:networkutils:aar:1.0.2'
<dependency org="com.pddstudio" name="networkutils" rev="1.0.2">
  <artifact name="networkutils" type="aar" />
</dependency>
@Grapes(
@Grab(group='com.pddstudio', module='networkutils', version='1.0.2')
)
libraryDependencies += "com.pddstudio" % "networkutils" % "1.0.2"
[com.pddstudio/networkutils "1.0.2"]

Dependencies

compile (3)

Group / Artifact Type Version
com.squareup.okhttp3 : okhttp jar 3.1.2
com.google.code.gson : gson jar 2.6.1
com.android.support » appcompat-v7 jar 23.3.0

Project Modules

There are no modules declared in this project.

#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

License

Maven Central

Minimum SDK

GitHub issues

Repository

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

Dependency

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

Installation

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.

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        //other stuff in your onCreate method...

        NetworkUtils.initSingleton(this);
    }

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:

    @Override
    protected void onCreate(final Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);
        //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

   http://www.apache.org/licenses/LICENSE-2.0

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.

Versions

Version
1.0.2
1.0.1
1.0.0