[android] 網路連結類型和渠道,android渠道
1.實現方式
1.1使用HttpUrlConnection
1.2使用HttpClient
1.3使用Socket,比如:豌豆莢,聊天工具
2.通訊渠道
2.1 WLAN(wi-fi),100米左右的資料轉送
2.2 手機APN存取點(基站)
2.2.1 wap的方式,中國特色,首先會串連電信電訊廠商代理攔截10.0.0.172,HttpUrlConnection會不穩定
2.2.2 net的方式
3.通訊工具
3.1判斷網路類型
根據Context上下文,判斷是wifi還是APN,然後再判斷APN的接入方式,有代理資訊的是wap沒有的是net
package com.tsh.lottery.net;import android.content.ContentResolver;import android.content.Context;import android.database.Cursor;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.net.Uri;public class NetUtils { /** * 擷取網路狀態 * @param context * @return */ public static String getNetworkInfo(Context context) { ConnectivityManager cm=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); //判斷wifi NetworkInfo networkInfo=cm.getNetworkInfo(ConnectivityManager.TYPE_WIFI); if(networkInfo!=null && networkInfo.isConnected()){ return "wifi"; } //判斷APN NetworkInfo mobileInfo=cm.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); if(mobileInfo!=null && mobileInfo.isConnected()){ //擷取APN接入方式,因為許可權問題,沒有成功// ContentResolver resolver=context.getContentResolver();// Cursor cursor=resolver.query(Uri.parse("content://telephony/carriers"), null, null, null, null);// if(cursor!=null && cursor.moveToFirst()){// String proxy=cursor.getString(cursor.getColumnIndex("proxy"));// System.out.println(proxy);// } return "mobile"; } return "no"; }}