Android judges the current network WiFi ctwap (cmwap) ctnet (cmnet)
Last Update:2018-12-06
Source: Internet
Author: User
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 textv Iew textview; Public void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); textview = new textview (this); textview. setbackgroundcolor (0 xffffffff); textview. settextcolor (0xff0000ff); textview. settextsize (15.0f); textview. setscrollbarstyle (textview. scrollbars_outside_overlay); scrollview = new scrollview (this); scrollview. addview (textview); setcontentview (scrollvi EW); 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 = 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 ("Arg =" + info. getarg () + "\ n"); textview. append ("SSID =" + info. getssid () + "\ n"); textview. append ("macaddress =" + info. getmacaddress () + "\ n");} public void initnetworkinfo () {connectivitymanager mag = (connectivitymanager) getsystemservice (context. connectivity_service); // output the textview of the currently available network. 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");} to: http://ming-fanglin.iteye.com/blog/805549