android-async-http开源项目可以是我们轻松的获取网络数据或者向server发送数据。使用起来很easy,关于android-async-http开源项目的介绍内容来自于官方:http://loopj.com/android-async-http/.以下我对此主页上内容进行大体上的翻译,希望可以对你理解android-async-http开源项目有所帮助

1.1 Overview(概况)

An asynchronous callback-based Http client for Android built on top of Apache’s HttpClient libraries.
All requests are made outside of your app’s main UI thread, but any callback logic will be executed on the same thread as the callback was created using Android’s Handler message passing.

译文:

异步基于回调的Httpclient为Android构建。是基于Apache HttpClient库的。全部的请求都是位于应用程序主线程 UI 之外,但不论什么回调逻辑将同样的线程上运行回调,使用Android的处理程序创建消息传递。

1.2 Features(特征)

  • Make asynchronous HTTP requests, handle responses in anonymous
    callbacks
  • 进行异步HTTP请求,处理响应在匿名回调中完毕
  • HTTP requests happen outside the UI thread
  • HTTP请求发生在UI线程之外
  • Requests use a threadpool to cap concurrent resource usage
  • 请求使用threadpool。限制并发资源使用情况
  • GET/POST params builder (RequestParams)
  • GET / POST參数构建使用(RequestParams)
  • Multipart file uploads with no additional third party libraries
  • Multipart 文件上传,没有额外的第三方库
  • Tiny size overhead to your application, only 25kb for everything
  • 在你的应用程序上利用非常小的开销,只25 kb就能够做一切
  • Automatic smart request retries optimized for spotty mobile
    connections
  • 自己主动智能请求重试,优化了质量不一的移动连接
  • Automatic gzip response decoding support for super-fast requests
  • 自己主动解码支持gzip反应速度超快的请求
  • Binary file (images etc) downloading with BinaryHttpResponseHandler
  • 二进制文件(图片等)的下载,使用BinaryHttpResponseHandler

  • Built-in response parsing into JSON with JsonHttpResponseHandler
  • 内置响应解析成JSON,使用JsonHttpResponseHandler

  • Persistent cookie store, saves cookies into your app’s SharedPreferences
  • 持久化cookie存储。保存cookie到你的应用程序的SharedPreferences

2.Installation & Basic Usage(安装和基本使用方法)

Download the latest .jar file from github and place it in your Android app’s libs/ folder.

从github上下载最新的最新的jar文件.并将其放置在你的Android应用程序的libs /目录.

2.1下载方式:

1.从http://loopj.com/android-async-http/的页面下载

点击DownLoad就可以下载最新的jar文件

2.从https://github.com/loopj/android-async-http的页面下载

找到DownLoad ZIP进行下载文件,解压后的文件夹例如以下

examples:里面有简单的样例

library:里面存放的是android-async-http开源项目的源代码(方法一:能够把library\src\main\java文件以下的文件复制到。你应用的src下也能够直接使用)

releases:里面存放的是各个版本号的jar文件。(方法二:仅仅需把最新的jar文件复制到你应用的libs文件夹下就可以.)

samples:里面存放的也是样例(可供參考)

备注:方法一和方法二仅仅能採用当中之中的一个。建议採用方法二

2.2用法

Import
the http package.

import com.loopj.android.http.*;

Create a new AsyncHttpClient instance and make a request:

AsyncHttpClient client = new AsyncHttpClient();
client.get("http://www.google.com", new AsyncHttpResponseHandler() {
@Override
public void onSuccess(String response) {
System.out.println(response);
}
});

Adding GET/POST Parameters with RequestParams

The RequestParams class is used to add optional GET or POST parameters to your requests.RequestParams can
be built and constructed in various ways:

Create empty RequestParams and immediately add some parameters:

RequestParams params = new RequestParams();
params.put("key", "value");
params.put("more", "data");

Create RequestParams for a single parameter:

RequestParams params = new RequestParams("single", "value");

Create RequestParams from an existing Map of
key/value strings:

HashMap<String, String> paramMap = new HashMap<String, String>();
paramMap.put("key", "value");
RequestParams params = new RequestParams(paramMap);

See the RequestParams Javadoc for more information.

Add an InputStream to the RequestParams to
upload:

InputStream myInputStream = blah;
RequestParams params = new RequestParams();
params.put("secret_passwords", myInputStream, "passwords.txt");

Add a File object to the RequestParams to
upload:

File myFile = new File("/path/to/file.png");
RequestParams params = new RequestParams();
try {
params.put("profile_picture", myFile);
} catch(FileNotFoundException e) {}

Add a byte array to the RequestParams to upload:

byte[] myByteArray = blah;
RequestParams params = new RequestParams();
params.put("soundtrack", new ByteArrayInputStream(myByteArray), "she-wolf.mp3");

See the RequestParams Javadoc for more information.

Downloading Binary Data with BinaryHttpResponseHandler

The BinaryHttpResponseHandler class can be used to fetch binary data such as images and other files. For example:

AsyncHttpClient client = new AsyncHttpClient();
String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" };
client.get("http://example.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) {
@Override
public void onSuccess(byte[] fileData) {
// Do something with the file
}
});

See the BinaryHttpResponseHandler Javadoc for more information.

08_android入门_android-async-http开源项目介绍及用法的更多相关文章

  1. windows下nodejs express安装及入门网站,视频资料,开源项目介绍

    windows下nodejs express安装及入门网站,视频资料,开源项目介绍,pm2,supervisor,npm,Pomelo,Grunt安装使用注意事项等总结 第一步:下载安装文件下载地址: ...

  2. 揭开webRTC媒体服务器的神秘面纱——WebRTC媒体服务器&开源项目介绍

    揭开webRTC媒体服务器的神秘面纱--WebRTC媒体服务器&开源项目介绍 WebRTC生态系统是非常庞大的.当我第一次尝试理解WebRTC时,网络资源之多让人难以置信.本文针对webRTC ...

  3. 6个P2P流媒体开源项目介绍

    P2P流媒体开源项目介绍  1. PeerCast 2002年成立,最早的开源P2P流媒体项目.PeerCast把节点按树结构组织起来, 每个频道都是一个树, 直播源是根节点,父节点只给子节点提供数据 ...

  4. P2P流媒体开源项目介绍

    P2P流媒体开源项目介绍1. PeerCast 2002年成立,最早的开源P2P流媒体项目.PeerCast把节点按树结构组织起来, 每个频道都是一个树, 直播源是根节点,父节点只给子节点提供数据.节 ...

  5. J2EE开发之常用开源项目介绍

    主要就我所了解的J2EE开发的框架或开源项目做个介绍,可以根据需求选用适当的开源组件进行开发.主要还是以Spring为核心,也总结了一些以前web开发常用的开源工具和开源类库 1持久层: 1)Hibe ...

  6. Google Go 语言从入门到应用必备开源项目

    Go 语言于 2009 年 11 月正式宣布推出,成为开放源代码项目,发展至今已经具有越来越广泛的影响力,今年更是在 TIOBE 编程语言排行榜中跻身 20 强.很多开发者也逐渐将目光投向这门语言,本 ...

  7. 【Android开发经验】移动设备的“声波通信/验证”的实现——SinVoice开源项目介绍(一)

    转载请注明出处:http://blog.csdn.net/zhaokaiqiang1992 在APP市场上,常常有一些充满新意的应用让我们眼前一亮,比方微信的面对面加好友,支付宝的声波支付等等,都是通 ...

  8. 移动端自动化openatx开源项目介绍,pytest并发测试框架结合

    开头 相信不少用过appium的同学,对于使用appium的一些体会与感受是否与我相似 1. appium启动服务和app程序非常慢 2. appium多线程并发需要启动多个服务 3. appium必 ...

  9. Insight API开源项目介绍

           首先,在阅读本文以前假设您已经了解比特币Bitcoin基本原理. Insight API是一个开源基于比特币Bitcoin  blockchain的REST风格的API框架.Insigh ...

随机推荐

  1. decimall类型数据

    同样是decimal(18,5)   和 decimal(18,4)  在VB中经过几次转化过后,数据就有可能改变. 遇到的情况 decimal(18,5)到  decimal(18,4)转换过程中数 ...

  2. 越狱开发:用iosOpenDev配置越狱开发环境 编写第一个hello world-b

    上网搜索越狱环境搭建,查到iosOpenDev软件,是个很方便的编写插件,而且可以直接用Xcode创建的工具,便开始着手学习如何去安装 集合了网上的方法后,我安装的时候发现: 1.作者最后更新的时间是 ...

  3. Test for open live write

    this is test document. this is test document. this is test document. this is test document. this is ...

  4. bzoj 3545&&3551: [ONTAK2010]Peaks &&加强版 平衡树&&并查集合并树&&主席树

    3545: [ONTAK2010]Peaks Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 635  Solved: 177[Submit][Stat ...

  5. tyvj P1716 - 上帝造题的七分钟 二维树状数组区间查询及修改 二维线段树

    P1716 - 上帝造题的七分钟 From Riatre    Normal (OI)总时限:50s    内存限制:128MB    代码长度限制:64KB 背景 Background 裸体就意味着 ...

  6. Codeforces Round #131 (Div. 2) : B

    首先能被2,5整除的数结尾必须是0: 如果没有0肯定不行: 然后判断他们的和ans%3: 如果==0,直接从大到小输出就行: 如果==1,要么删除它们之间最小的那个%3==1的,要么删除两个小的并且% ...

  7. node场景

    http://www.zhihu.com/question/19653241 http://www.csdn.net/article/2012-05-03/2805296 http://limu.it ...

  8. 为什么用GPU挖比特币?

    http://www.leiphone.com/gpubitcoin.html 呵呵,这么红火的东东,不了解就长不了见识. 转一下两个东东,这挖矿机天天在算什么内容,还有,当前为什么GPU比CPU有优 ...

  9. SqlTransaction的解析

    SqlTransaction的解析 2011-10-10 19:48 2757人阅读 评论(1) 收藏 举报 exceptionsql serverinsertcommandobjectstring ...

  10. Keil 的调试命令、在线汇编与断点设置

    上一讲中我们学习了如何建立工程.汇编.连接工程,并获得目标代码,但是做到这一 步仅仅代表你的源程序没有语法错误,至于源程序中存在着的其它错误,必须通过调试才能 发现并解决,事实上,除了极简单的程序以外 ...