GithubHelp home page GithubHelp logo

cjq / android-volley-manager Goto Github PK

View Code? Open in Web Editor NEW

This project forked from panxw/android-volley-manager

0.0 2.0 0.0 2.82 MB

Android Volley Manager is based on Google's Android Volley, powered by HttpURLConnection, JSON, XML, Map, RequestMap(with file) request supported.

Java 100.00%

android-volley-manager's Introduction

Android Volley Manager

##About Android Volley Manager is based on Google's Android Volley.
Powered by HttpURLConnection, no HttpClient need now!(HttpClient is Deprecated in Android 5.1)
JSON, XML, Map, RequestMap(with file) request supported.
Android 2.3+(API>=9) is required.
Tested in Android 5.1, 6.0.

##### Download

##Usage #####for Maven com.panxw.volley library 1.0.1

#####for Gradle dependencies { compile 'com.panxw.volley:library:1.0.1' }

#####latest jars for download com.panxw.volley-1.0.1-classes.jar

##Sample #####init RequestManager in your Application public class VolleyApplication extends Application { @Override public void onCreate() { super.onCreate(); RequestManager.getInstance().init(this); }

	@Override
	public void onTerminate() {
		super.onTerminate();
	}
}

#####use RequestManager to load data public class MainActivity extends Activity implements RequestListener { private static final String OUT_FILE = "upload.txt"; private static final String OUT_DATA = "sadf464764sdf3ds1f3adsf78921355u2390q3rtheslafkhsdafhreasof"; private static final String POST_URL = "http://allthelucky.ap01.aws.af.cm/memoServer"; private static final String POST_JSON = "{"action":"test", "info":"hello world"}"; private static final String GET_URL = "https://raw.githubusercontent.com/panxw/android-volley-manager/master/test.txt"; private static final String UPLOAD_URL = "http://www.splashpadmobile.com/upload.php"; private LoadController mLoadController = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		this.testPost();
		this.testGet();
		this.testFileUpload();
	}
	
	private void testPost() {//test post 
		mLoadController = RequestManager.getInstance().post(POST_URL, POST_JSON, this, 0);
	}
	
	private void testGet() {//test GET
		mLoadController = RequestManager.getInstance().get(GET_URL, this, 1);
	}
	
	private void testFileUpload() {//test POST(with file) in RequestMap
		MainActivity.prepareFile(this);

		RequestMap params = new RequestMap();
		File uploadFile = new File(this.getFilesDir(), OUT_FILE);
		params.put("uploadedfile", uploadFile);
		params.put("share", "1");

		mLoadController = RequestManager.getInstance().post(UPLOAD_URL, params, this, 2);
	}

	@Override
	public void onSuccess(String response, Map<String, String> headers,
			String url, int actionId) {
		System.out.println("actionId:" + actionId + ", OnSucess!\n" + response);
	}

	@Override
	public void onError(String errorMsg, String url, int actionId) {
		System.out.println("actionId:" + actionId + ", onError!\n" + errorMsg);
	}

	@Override
	public void onRequest() {
		System.out.println("request send...");
	}

	@Override
	public void onBackPressed() {
		super.onBackPressed();
		if (mLoadController != null) {
			mLoadController.cancel();
		}
	}

	private static void prepareFile(Context context) {
		FileOutputStream fos = null;
		try {
			fos = context.openFileOutput(OUT_FILE, Context.MODE_PRIVATE);
			try {
				fos.write(OUT_DATA.getBytes());
			} catch (IOException e) {
				e.printStackTrace();
			}
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		} finally {
			if (fos != null) {
				try {
					fos.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
	}
}

#####Author GitHub: https://github.com/panxw
Linkedin: http://www.linkedin.com/in/panxw
QQ: 85902258

License

Copyright (C) 2011 The Android Open Source Project

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.

android-volley-manager's People

Contributors

mengyxinx avatar panxw avatar

Watchers

 avatar  avatar

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.