深入学习Android有关网络连接的内容
基于实际项目中碰到的些许问题,开始重新深入学习Android网络连接有关知识。
Android的4.1.2版本的AndroidHttpClient模块setSoTimeout之后实际超时时间和设置的时间不一致现象
不知何种原因,高版本平台使用AndroidHttpClient(setSoTimeout设置的超时时间为60秒),实际反应出的超时时间不一致,需要4分钟才超时。 设备1:U880(2.2平台)实际超时时间 = setSoTimeout的时间 设备2:J2(4.1.2平台)实际超时时间 = setSoTimeout的时间 * 4倍
参考资料:
Connecting to the Network | Android Developers
http://developer.android.com/intl/zh-cn/training/basics/network-ops/connecting.html- 官方讨论博客:选择最佳HTTP Client
http://android-developers.blogspot.com/2011/09/androids-http-clients.html(需自带梯子)Android访问网络,使用HttpURLConnection还是HttpClient? - 郭霖的专栏 - 博客频道 - CSDN.NET(翻译好的)
Which client is best?
Apache HTTP client has fewer bugs on Eclair(2.0) and Froyo(2.2). It is the best choice for these releases. For Gingerbread(2.3) and better, HttpURLConnection is the best choice. Its simple API and small size makes it great fit for Android. Transparent compression and response caching reduce network use, improve speed and save battery. New applications should use HttpURLConnection; it is where we will be spending our energy going forward. - 官方API文档 | Android Developers
http://developer.android.com/intl/zh-cn/reference/java/net/HttpURLConnection.html
开源的针对 HttpURLConnection 的封装,里面还有介绍许多别的开源组件
hgoebl/DavidWebb · GitHub
https://github.com/hgoebl/DavidWebb#not-for-you较简单的介绍How to use java.net.URLConnection to fire and handle HTTP requests? - Stack Overflow
- 较简单的封装basic-http-client - Basic HTTP client w/ Android AsyncTask wrapper - Google Project Hosting
知识小结:
- Android的HTTP Client 有:
1.Apache 的DefaultHttpClient 或 Android基于此再封装一次的 AndroidHttpClient
2.JAVA 的 HttpURLConnection,不过兼容低版本时需注意的有:private void disableConnectionReuseIfNecessary() {
// HTTP connection reuse which was buggy pre-froyo
if (Integer.parseInt(Build.VERSION.SDK) < Build.VERSION_CODES.FROYO) {
System.setProperty("http.keepAlive", "false");
}
}
- Android的HTTP Client 有:
深入学习Android有关网络连接的内容的更多相关文章
- Android检测网络连接
Android检测网络连接 import android.app.AlertDialog; import android.content.Context; import android.content ...
- android 检查网络连接状态实现步骤
获取网络信息需要在AndroidManifest.xml文件中加入相应的权限. <uses-permission android:name="android.permission.AC ...
- Android 检测网络连接状态
Android连接网络的时候,并不是每次都能连接到网络,因此在程序启动中需要对网络的状态进行判断,如果没有网络则提醒用户进行设置. 首先,要判断网络状态,需要有相应的权限,下面为权限代码(Androi ...
- android当前网络连接类型判断
package net.nyist.netState; import android.content.Context; import android.net.ConnectivityManager; ...
- android检测网络连接状态示例讲解
网络的时候,并不是每次都能连接到网络,因此在程序启动中需要对网络的状态进行判断,如果没有网络则提醒用户进行设置 Android连接首先,要判断网络状态,需要有相应的权限,下面为权限代码(Andro ...
- android检查网络连接状态的变化,无网络时跳转到设置界面
在AndroidManifest.xml中加一个声明<receiver android:name="NetCheckReceiver"> <intent-filt ...
- [Android]推断网络连接是否可用
/** * 推断移动网络是否开启 * * @param context * @return */ public static boolean isNetEnabled(Context context) ...
- Android OkHttp网络连接封装工具类
package com.lidong.demo.utils; import android.os.Handler; import android.os.Looper; import com.googl ...
- android判断网络连接状态、联网类型、运营商
/** * 获取上网方式 * * @param mContext * @return */ public static String getNetType(Context mContext) { St ...
随机推荐
- Ubuntu 装JDK
我是按照这篇文章安装jdk的: http://www.cnblogs.com/bluestorm/archive/2012/05/10/2493592.html 先去 Oracle下载Linux下 ...
- Spring多资源文件properties的配置
Spring简化了加载资源文件的配置,可以通过<context:property-placeholder去加载,这个元素的写法如下: <context:property-placehold ...
- lintcode :Trailing Zeros 尾部的零
题目: 尾部的零 设计一个算法,计算出n阶乘中尾部零的个数 样例 11! = 39916800,因此应该返回 2 挑战 O(logN)的时间复杂度 解题: 常用方法: 也许你在编程之美中看到,通过求能 ...
- 257. Binary Tree Paths
题目: Given a binary tree, return all root-to-leaf paths. For example, given the following binary tree ...
- swift:高级运算符(位运算符、溢出运算符、优先级和结合性、运算符重载函数)
swift:高级运算符 http://www.cocoachina.com/ios/20140612/8794.html 除了基本操作符中所讲的运算符,Swift还有许多复杂的高级运算符,包括了C语和 ...
- 【原创】中文分词系统 ICTCLAS2015 的JAVA封装和多线程执行(附代码)
本文针对的问题是 ICTCLAS2015 的多线程分词,为了实现多线程做了简单的JAVA封装.如果有需要可以自行进一步封装其它接口. 首先ICTCLAS2015的传送门(http://ictclas. ...
- sudo
sudo的目的:为非根用户授予根用户的权限: 配置文件:/etc/sudoers visudo命令编辑修改/etc/sudoers配置文件 1.一般用户赋权设置: [root@localhost ~] ...
- android的ScaleGestureDetector缩放类详解
文章由多出组合,它们来自: http://elvajxw.iteye.com/blog/1308452 http://www.cnblogs.com/lknlfy/archive/2012/03/11 ...
- 在Windows下利用php自带的mail函数发邮件
这几天看<Head First PHP & MySQL>,里面有发邮件的例子是用系统自带的mail函数发送的,自己照书上写的试了一直不成功,后来终于在网上找到解决方案,现在总结下. ...
- UVa 10088 (Pick定理) Trees on My Island
这种1A的感觉真好 #include <cstdio> #include <vector> #include <cmath> using namespace std ...