zoukankan      html  css  js  c++  java
  • 如何判断当前手机网络是cmwap还是cmnet?

           如何想知道当前手机网络是 CMWAP 还是CMNET?首先咱们来了解一下APN的概念

            APN的英文全称是Access Point Name,中文全称叫接入点,是您在通过手机上网时必须配置的一个参数,它决定了您的手机通过哪种接入方式来访问网络。用来标识GPRS的业务种类,目前分为两大类:CMWAP/UNIWAP/3GWAP(通过GPRS访问WAP业务)、CMNET/UNINET/3GNET(除了WAP以外的服务目前都用CMNET,比如连接因特网等)。

          现网中,APN=cmnet就代表internet, APN=cmwap就代表专用WAP数据网络,当然各个运营商可能名字不一样,如联通是uniwap,uninet等。
          现在我们涉及到的APN具体有两种,一种是通过手机浏览器上网使用的,另一种是通过客户端软件来登陆服务器。中国联通的2G业务WAP浏览器中使用的APN为“UNIWAP”,3G业务WAP浏览器使用的APN为“3GWAP”;中国联通的2G上公网使用的APN为“UNINET”,3G业务上网卡及上公网使用的APN为“3GNET”。 中国移动上内网的APN为“CMWAP”,上网卡及上公网使用的APN为“CMNET”。 中国电信上内网的APN为“CTWAP”,上网卡及上公网使用的APN为“CTNET”。

            关于Android代码中如何获得当前手机网络是cmwap还是cmnew,下面上一段代码,不解释,自己看去吧。

          

    package lab.sodino.net;
    
    import java.net.InetAddress;
    
    import android.app.Activity;
    import android.content.Context;
    import android.net.ConnectivityManager;
    import android.net.NetworkInfo;
    import android.net.wifi.WifiInfo;
    import android.net.wifi.WifiManager;
    import android.os.Bundle;
    import android.widget.ScrollView;
    import android.widget.TextView;
    
    public class NetAct extends Activity {
        private TextView textView;
    
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            textView = new TextView(this);
            textView.setBackgroundColor(0xffffffff);
            textView.setTextColor(0xff0000ff);
            textView.setTextSize(15.0f);
            textView.setScrollBarStyle(TextView.SCROLLBARS_OUTSIDE_OVERLAY);
    
            ScrollView scrollView = new ScrollView(this);
            scrollView.addView(textView);
            setContentView(scrollView);
            getLocalHost();
            getWifiInfo();
            initNetworkInfo();
        }
    
        private void getLocalHost() {
            try {
                InetAddress iAdd = InetAddress.getLocalHost();
                String line = "";
                String hostName = iAdd.getHostName();
                if (hostName != null) {
                    InetAddress[] adds = InetAddress.getAllByName(hostName);
                    for (int i = 0; i < adds.length; i++) {
                        iAdd = adds[i];
                        line = "HostName=" + iAdd.getHostName() + "\n";
                        textView.append(line);
                        line = "CanonicalHostName=" + iAdd.getCanonicalHostName()
                                + "\n";
                        textView.append(line);
                        line = "HostAddress=" + iAdd.getHostAddress() + "\n";
                        textView.append(line);
                        textView.append("\n");
                    }
                }
            } catch (Exception e) {
                e.printStackTrace();
    
            }
        }
    
        public void getWifiInfo() {
            WifiManager wifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
            WifiInfo info = wifi.getConnectionInfo();
            textView.append("HiddenSSID=" + info.getHiddenSSID() + "\n");
            textView.append("IpAddress=" + info.getIpAddress() + "\n");
            textView.append("LinkSpeed=" + info.getLinkSpeed() + "\n");
            textView.append("NetworkId=" + info.getNetworkId() + "\n");
            textView.append("Rssi=" + info.getRssi() + "\n");
            textView.append("SSID=" + info.getSSID() + "\n");
            textView.append("MacAddress=" + info.getMacAddress() + "\n");
        }
    
        public void initNetworkInfo() {
            ConnectivityManager mag = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
            // 此处输出当前可用网络
            textView.append("\nActive:\n");
            NetworkInfo info = mag.getActiveNetworkInfo();
            textView.append("ExtraInfo=" + info.getExtraInfo() + "\n");
            textView.append("SubtypeName=" + info.getSubtypeName() + "\n");
            textView.append("TypeName=" + info.getTypeName() + "\n");
    
            textView.append("\nWifi:\n");
            NetworkInfo wifiInfo = mag
                    .getNetworkInfo(ConnectivityManager.TYPE_WIFI);
    
            textView.append("ExtraInfo=" + wifiInfo.getExtraInfo() + "\n");
            textView.append("SubtypeName=" + wifiInfo.getSubtypeName() + "\n");
            textView.append("TypeName=" + wifiInfo.getTypeName() + "\n");
            NetworkInfo mobInfo = mag
                    .getNetworkInfo(ConnectivityManager.TYPE_MOBILE);
            textView.append("\nMobile:\n");
            textView.append("ExtraInfo=" + mobInfo.getExtraInfo() + "\n");
            textView.append("SubtypeName=" + mobInfo.getSubtypeName() + "\n");
            textView.append("TypeName=" + mobInfo.getTypeName() + "\n");
        }
    }

    需要加入权限:

        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
  • 相关阅读:
    springboot成神之——websocket发送和请求消息
    springboot成神之——发送邮件
    springboot成神之——spring文件下载功能
    springboot成神之——spring的文件上传
    springboot成神之——basic auth和JWT验证结合
    springboot成神之——Basic Auth应用
    leetcode-easy-array-122 best time to buy and sell stocks II
    leetcode-easy-array-31 three sum
    leetcode-mid-others-621. Task Scheduler
    leetcode-mid-math-371. Sum of Two Integers-NO-???
  • 原文地址:https://www.cnblogs.com/yejiurui/p/2985165.html
Copyright © 2011-2022 走看看