編輯:關於Android編程
代碼如下,直接嵌入程序可用!
/**
* 針對圖片下載的代理設置;
* 獲取動態代理的HttpURLConnection
* @param url 請求的url地址;
* @return HttpURLConnection 可以直接進行數據操作;
* @throws IOException
*
* 設置代理
* 設置頭
* 設置連接;
* 設置統計時間;
*/
public HttpURLConnection getDynamicNetWorkHttpURLConnection( HttpURLConnection httpURLConnection, String url ) throws IOException {
URL mURL = new URL( url );
if( DynamicNetWork.mConnectType == 0 ) {
if(mCurrentApnName == null){
mCurrentApnName = getCurrentApnInUse( context );
}
/** 移動的代理連接 */
if( mCurrentApnName.startsWith( CMWAP ) ) {
String mDomainName = getDomainName( url );
url = url.replace(mDomainName, mWAPLocalHost );
httpURLConnection = ( HttpURLConnection )mURL.openConnection();
httpURLConnection.setRequestProperty( "X-Online-Host", mDomainName );
/** 聯通的代理連接 */
}else if( mCurrentApnName.startsWith( UNIWAP ) || mCurrentApnName.startsWith( G3WAP )){
InetSocketAddress inetAddress = new InetSocketAddress( mWAPLocalHost, 80 );
java.net.Proxy.Type proxyType = java.net.Proxy.Type.valueOf( mURL.getProtocol().toUpperCase() );
java.net.Proxy javaProxy = new java.net.Proxy( proxyType, inetAddress );
httpURLConnection = ( HttpURLConnection )mURL.openConnection( javaProxy );
}else /** 電信的代理連接 */
if( mCurrentApnName.startsWith( CTWAP ) ) {
InetSocketAddress inetAddress = new InetSocketAddress( mCDMALocalHost, 80 );
java.net.Proxy.Type proxyType = java.net.Proxy.Type.valueOf( mURL.getProtocol().toUpperCase() );
java.net.Proxy javaProxy = new java.net.Proxy( proxyType, inetAddress );
httpURLConnection = ( HttpURLConnection )mURL.openConnection( javaProxy );
}
} else {
httpURLConnection = ( HttpURLConnection )mURL.openConnection();
}
httpURLConnection.connect();
return httpURLConnection;
}
/**獲取當前網絡名稱;
* @param mcontext
* @return
*/
public static String getCurrentApnInUse( Context mcontext ) {
String name = "no";
ConnectivityManager manager = ( ConnectivityManager )mcontext.getSystemService( Context.CONNECTIVITY_SERVICE );
try {
NetworkInfo activeNetInfo = manager.getActiveNetworkInfo();
if( activeNetInfo != null && activeNetInfo.isAvailable() ) {
name = activeNetInfo.getExtraInfo();
}
} catch( Exception e ) {
e.printStackTrace();
}
return name;
}
/**獲取當前代理
* @param currentName
* @return
*/
public static String getApnProxy( String currentName ) {
if( "".equals( currentName ) || null == currentName ) {
return "";
}
currentName = currentName.toLowerCase();
if( currentName.startsWith( CMWAP ) || currentName.startsWith( UNIWAP ) || currentName.startsWith( G3WAP ) )
return CMCC_WAPPROXY;
else if( currentName.startsWith( CTWAP ) )
return CMCC_CDMAPROXY;
else
return "";
}
前言Android內置webkit內核的高性能浏覽器,而WebView則是在這個基礎上進行封裝後的一個 控件,WebView直譯網頁視圖,我們可以簡單的看作一個可以嵌套到
首先,自定義控件分為三類:自定義的組合控件繼承View的自定義控件繼承ViewGroup的自定義控件在這裡,我要寫的是第二種,也就是繼承自View的自定義控件,第一種自定
今天我們來講一下Android中BroadcastReceiver的相關知識。BroadcastReceiver也就是“廣播接收者”的意思,顧名思義,它就是用來接收來自系
本文實例實現了兩個模擬器之間短信的發送功能,分享給大家供大家參考,具體實現內容如下1.編輯String.xml文件內容為:<?xml version=”1.