The difference between Android system NET and WAP access point _android

Source: Internet
Author: User

When we use the Android device to connect to the network, if it is a WAP access point need to set up agents, and telecommunications and mobile unicom agent is not the same, mobile and Unicom WAP agent is 10.0.0.172:80, Telecom WAP agent is 10.0.0.200 : 80, so it is necessary to determine the access point for Android development.

type of Access point

NET Network: operator (mobile Unicom Telecom) NET network, WIFI,USB network sharing

WAP Network: Mobile Unicom WAP (Agent same: 10.0.0.172:80), Telecom WAP (agent: 10.0.0.200:80)

This seems to be able to abstract three types of network: Unicom Mobile WAP, Telecom WAP, the other is net type.

Access Point Judgment instance

The example code of the access point judgment is given below, and some annotations are made, which are some points needing attention in the actual project development. Share them for your reference.

Java code

Package com.johnson.utils;  
Import COM.SHOOWC.R;  
Import android.app.Activity;  
Import Android.content.Context;  
Import Android.database.Cursor;  
Import Android.net.ConnectivityManager;  
Import Android.net.NetworkInfo;  
Import Android.net.Uri;  
Import Android.os.Bundle;  
Import Android.text.TextUtils;  
 
Import Android.util.Log; The public class Ex01_checkapntypeactivity extends activity {/** called the ' when the ' is the ' The activity ' is a./Public s  
 Tatic final String ctwap = "Ctwap";  
 public static final String Cmwap = "Cmwap";  
 public static final String wap_3g = "3gwap";  
 public static final String Uniwap = "Uniwap"; public static final int type_net_work_disabled = 0;//network unavailable public static final int type_cm_cu_wap = 4;//Mobile Unicom wap10.0 .0.172 public static final int type_ct_wap = 5;//Telecom WAP 10.0.0.200 public static final int type_other_net = 6;//Power Letter, Mobile, Unicom, WiFi net network public static Uri Preferred_apn_uri = URI. Parse ("Content://telephony/carrierS/PREFERAPN ");  
  @Override public void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate);  
 
  Setcontentview (R.layout.main);  
 Checknetworktype (this); /*** * Network Specific type (Unicom mobile WAP, Telecom WAP, other net) * */public static int Checknetworktype (context Mcontex T) {try {final connectivitymanager Connectivitymanager = (connectivitymanager) mcontext. Getsystemservic  
   E (Context.connectivity_service);  
   Final Networkinfo mobnetinfoactivity = Connectivitymanager. Getactivenetworkinfo (); if (mobnetinfoactivity = null | |!mobnetinfoactivity.isavailable ()) {//Note one://Networkinfo is empty or cannot be  
    The normal situation should be that there is currently no available network,//But some telecommunications machines, still can be normal networking,//So as NET network processing still try to connect the network.  
      
    (then catch the exception in the socket, make two judgments and user prompts).  
    LOG.I ("", "=====================> No Network");  
   return type_other_net;  
   The else {//Networkinfo is not null start judgment is the network type int nettype = Mobnetinfoactivity.gettype (); if (NetType = = Connectivitymanager.type_wifi) {//WIFI net processing log.i ("", "=====================>wifi Network");  
    return type_other_net; else if (NetType = = Connectivitymanager.type_mobile) {//Note II://To determine whether the telecommunications WAP://Do not pass the GetEx  Trainfo gets the access point name to determine the type,//because through the current telecommunications a variety of model tests found that the access point name is mostly #777 or NULL,//Telecom machine WAP access point than Mobile Unicom WAP access point more than set a username and password,/  
 
     So it can be judged by this!  
     Final Cursor C = mcontext.getcontentresolver (). query (Preferred_apn_uri, NULL, NULL, NULL, NULL);  
      if (c!= null) {C.movetofirst ();  
      Final String user = C.getstring (c. Getcolumnindex ("user")); if (!  
             Textutils.isempty (user)) {log.i ("", "=====================> Agent:" + c.getstring (c  
       . Getcolumnindex ("proxy"));  
        if (User.startswith (Ctwap)) {log.i ("", "=====================> Telecommunications WAP Network");  
       return type_ct_wap; }}} C.CLose (); Note Three://The decision is mobile Unicom WAP://In fact, there is a way through GetString (C.getcolumnindex ("proxy") to obtain proxy IP//To determine the access point, 10.0.0.172 is mobile  
        
     Unicom wap,10.0.0.200 is the telecommunications WAP, but in the actual development of not all machines can get access point agent information, such as the charm of the M9 (2.2) and so on ...//so use Getextrainfo to get access point name to judge  
     String Netmode = Mobnetinfoactivity.getextrainfo ();  
     LOG.I ("", "Netmode ==================" + netmode);  
      if (Netmode!= null) {//By the APN name to determine whether the Unicom and mobile WAP netmode=netmode.tolowercase (); if (netmode.equals (cmwap) | | | netmode.equals (WAP_3G) | | netmode.equals (UNIWAP)) {log.i ("", "===========  
       ==========> Mobile Unicom WAP Network ");  
      return type_cm_cu_wap;  
   catch (Exception ex) {Ex.printstacktrace ()}}}}  
  return type_other_net;  
 
 return type_other_net; 
 }  
}

The above is a complete example code, plus a detailed annotation, I believe we can see very clear.

Through this article, I hope to help everyone, thank you for your support to this site!

Related Article

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.