[Android] network link types and channels

Source: Internet
Author: User

1. How to Implement

1.1 using httpurlconnection

1.2 using HttpClient

1.3 using sockets, such as: pea pods, chat tools

2. Communication channels

2.1 WLAN (Wi-Fi), data transfer around the meter

2.2 Mobile APN access point (Base station)

2.2.1 Wap Way, Chinese characteristics, first will connect the carrier agent to intercept 10.0.0.172,httpurlconnection will be unstable

The 2.2.2 Net way

3. Communication tools

3.1 determine the network type

Depending on the context, determine whether WiFi or APN, and then determine the APN access method, There is proxy information is the WAP is not the net

 Packagecom.tsh.lottery.net;ImportAndroid.content.ContentResolver;ImportAndroid.content.Context;ImportAndroid.database.Cursor;ImportAndroid.net.ConnectivityManager;ImportAndroid.net.NetworkInfo;ImportAndroid.net.Uri; Public classNetUtils {/*** Get network status *@paramContext *@return     */     Public StaticString Getnetworkinfo (context context) {Connectivitymanager cm=(Connectivitymanager) Context.getsystemservice (Context.connectivity_service); //Judging WiFiNetworkinfo networkinfo=Cm.getnetworkinfo (Connectivitymanager.type_wifi); if(networkinfo!=NULL&&networkinfo.isconnected ()) {            return"WiFi"; }        //determine APNNetworkinfo mobileinfo=Cm.getnetworkinfo (Connectivitymanager.type_mobile); if(mobileinfo!=NULL&&mobileinfo.isconnected ()) {            //Access to APN access mode because of a permissions issue that did not succeed//contentresolver resolver=context.getcontentresolver ();//Cursor cursor=resolver.query (Uri.parse ("Content://telephony/carriers "), null , NULL, NULL, and NULL);//if (cursor!=null && Cursor.movetofirst ()) {//String proxy=cursor.getstring (Cursor.getcolumnindex ("proxy"));//System.out.println (proxy);//            }            return"Mobile"; }        return"No"; }}

[Android] network link types and channels

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.