GithubHelp home page GithubHelp logo

jamieomatthews / androidnetworking Goto Github PK

View Code? Open in Web Editor NEW
1.0 3.0 1.0 172 KB

Android Networking Kit is a framework for routing simple network requests with minimal code for Android OS

Java 100.00%

androidnetworking's Introduction

AndroidNetworkKit

Android Networking Kit is a framework for routing simple network requests with minimal code for Android. It provides an easy way to integrate your activity with powerful network requests, while keeping your activities clean and readable.

The sample MainActivity gives a simple example of using the Spotify API to route a request, parse, and display it.

##Setting up your activity First, you must override the ANTask and ANHandler in your activity.

public class GetData extends ANTask{
	public GetData(String URL, String action, List<NameValuePair> params,
			String type, Handler mainUIHandler, Context context) {
		super(URL, action, params, type, mainUIHandler, context);
	}

	@Override
	protected Object decode(String jsondata) throws JSONException {
		//decode json data here
	}
}
ANHandler asyncHandler = new ANHandler()
{
	@Override
	public void resultOK(Message msg) 
	{
		//get your returned object here
		Object ob = msg.obj;
	}
	@Override
	public void resultFailed(Message msg) {
		//Show some error message
	}
};

##Making the request public ANTask(String URL, String action, List params, String type, Handler mainUIHandler, Context context) To make a request, you must sepecify the following options:

  • URL - (String) The url to route to. The base url is set in the ANTask class
  • Action - (String) GET or POST
  • Name Value Pairs - (BasicNameValuePair) Used for both get and post. For a post, these are form encoded. For get, they are URL encoded and appended to the get string
  • Type - (String) This is passed back by the handler for differentiating between requests. Passed back as msg.what
  • Handler - (ANHandler) Your ANHandler created above
  • Context - (Context) Your activities context

##Basic Auth

For basic auth support, use the ANUtils class to set a username and password in preferences, and it will be used for every request. public void setLogin(String username, String password)

##Notes

  • The decode method exposes the parsing method in your main activity, so you can have the applicable code right in your activity, while hiding all the ugly networking code
  • Return any Object from the decode method, and then recieve it in the resultOk by calling msg.obj;
  • If null is returned from decode, resultFailed will be called
  • For json data parsing, check out google GSON for easy parsing

##Copyright 2012 MindBlownInnovation

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.

androidnetworking's People

Contributors

jamieomatthews avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

Forkers

hhhle

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.