深入学习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 ...
随机推荐
- hdu2013
http://acm.hdu.edu.cn/showproblem.php?pid=2013 #include<iostream> #include<stdio.h> #inc ...
- Project Euler 75:Singular integer right triangles
题目链接 原题: It turns out that 12 cm is the smallest length of wire that can be bent to form an integer ...
- ASP.Net WebForm学习笔记:一、aspx与服务器控件探秘
作者:周旭龙 出处:http://edisonchou.cnblogs.com 开篇:毫无疑问,ASP.Net WebForm是微软推出的一个跨时代的Web开发模式,它将WinForm开发模式的快捷便 ...
- STL函数模板(即算法)一览
查找算法 adjacent_find:找出一个串中第一个不符合次序的地方 find,find_if:找出第一个符合条件的元素 find_first_of:在一个串中寻找第一个与另一个串中任意一个元素相 ...
- PHP中的抽象类与接口
抽象类 php5支持抽象类和抽象方法.类前加 abstract, 此类就成为抽象类,无法被实例化,此类天生就是用来被继承的,给子类提供了一个类的模板; 类方法前加 abstract,是抽象方法,抽象方 ...
- python logging 学习笔记
logging.basicConfig函数各参数: filename: 指定日志文件名 filemode: 和file函数意义相同,指定日志文件的打开模式,'w'或'a' format: 指定输出的格 ...
- Unix编程之size_t、ssize_t
http://blog.csdn.net/lalor/article/details/7426184 首先,我非常肯定以 及确定的告诉你ssize_t是有符号整型,在32位机器上等同与int,在64位 ...
- CentOS7安装Hadoop2.7完整流程
总体思路,准备主从服务器,配置主服务器可以无密码SSH登录从服务器,解压安装JDK,解压安装Hadoop,配置hdfs.mapreduce等主从关系. 1.环境,3台CentOS7,64位,Hadoo ...
- Android开发之EditText属性详解
1.EditText输入的文字为密码形式的设置 (1)通过.xml里设置: 把该EditText设为:android:password="true" // 以”.”形式显示文本 ( ...
- poj3307
可以证明,每个符合的数都由2,3,5,7相乘得到. 依据猜想:下一个出现的数是由前面某个数乘上这几个数之一得到的新的数. 假设之前的数均满足序列,则因为下一个数必有2,3,5,7相乘得到,而这个数之前 ...