NetworkUtils


Source link: https://github.com/PDDStudio/NetworkUtils

#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

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. 

Resources

Telegram and whatsapp like download progress indicator.

Ultimate RecyclerView.

This framework is designed to solve the traditional MVP class and interface too much, and Presenter and View communicate too complicated through the interface, reuse Presenter too much cost.

Marvelous sliding square loader view inspired this.

The lib provides an easy way to store your settings in SharedPreferences.

Using Html to render Android native view.

Other than Webview, HtmlNative directly parses HTML and CSS into Android native views, which will:

  • Reach better user-expirence by native widgets
  • Make UI dynamic, no need to release new version of application
  • Easy to write html and css
  • Define your own html tag
  • Support script of Lua, by which you can control the logic inside of this view.

Topics


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