1 Star 0 Fork 0

xiaoqiang/android-volley-manager

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
贡献代码
同步代码
取消
提示: 由于 Git 不支持空文件夾,创建文件夹后会生成空的 .keep 文件
Loading...
README

Android Volley Manager

##About 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.

Update

Version: v1.0.2
Date: 2016-05-02
Desc: fix header bug and add gzip support
JCenter->Download

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

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

#####latest jars for download com.panxw.volley-1.0.2-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 TAG = "VolleyTest";

	private static final String GET_URL = "http://www.panxw.com/about.html";

	private static final String POST_URL = "http://www.panxw.com/index.php";

	private static final String POST_JSON = "{\"action\":\"test\", \"info\":\"hello world\"}";

	private static final String OUT_FILE = "upload.txt";

	private static final String OUT_DATA = "df464764sdf3ds1f3adsf789213557r12-34912-482130487321";

	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.testGet();
		this.testPost();
		this.testFileUpload();
	}

	private void testGet() {
		mLoadController = RequestManager.getInstance().get(GET_URL, this, 1);
	}

	private void testPost() {
		mLoadController = RequestManager.getInstance().post(POST_URL, POST_JSON,
				this, 0);
	}

	private void testFileUpload() {
		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) {
		Log.d(TAG, "actionId:" + actionId + ", OnSucess!\n" + response);
	}

	@Override
	public void onError(String errorMsg, String url, int actionId) {
		Log.d(TAG, "actionId:" + actionId + ", onError!\n" + errorMsg);
	}

	@Override
	public void onRequest() {
		Log.d(TAG, "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 Blog: http://www.panxw.com
Linkedin: http://www.linkedin.com/in/panxw
QQ交流群: 168563980

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 by HttpURLConnection(no HttpClient need), JSON, XML, Map, RequestMap(with file) request supported. 展开 收起
取消

发行版

暂无发行版

贡献者

全部

语言

近期动态

不能加载更多了
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Java
1
https://gitee.com/codeing_q/android-volley-manager.git
git@gitee.com:codeing_q/android-volley-manager.git
codeing_q
android-volley-manager
android-volley-manager
master

搜索帮助