Android gets the WiFi information of the current connection

Source: Internet
Author: User
Tags bssid
Package COM. lenovo. xiaoshan. test; import android. app. activity; import android. bluetooth. export thadapter; import android. content. context; import android. content. intent; import android.net. wiFi. wifiinfo; import android.net. wiFi. wifimanager; import android. OS. bundle; import android. widget. textview;/*** get the MAC address of the phone WiFi * @ author single redwoo **/public class getmacipinfoactivity extends activity {/** called when Ctivity is first created. */Private Static final int request_enable_bt = 3; private wifimanager mwifi; private string wifimac; @ overridepublic void oncreate (bundle savedinstancestate) {super. oncreate (savedinstancestate); setcontentview (R. layout. main); mwifi = (wifimanager) getsystemservice (context. wifi_service); If (! Mwifi. iswifienabled () {mwifi. setwifienabled (true);} wifiinfo = mwifi. getconnectioninfo (); If (wifimac = wifiinfo. getmacaddress () = NULL) {wifimac = "no wifi device";} textview MAC = (textview) findviewbyid (R. id. macview); Mac. settextsize (16); // view the connected Wi-Fi information. In the android SDK, we provide an object called wifiinfo, which can be used by wifimanager. getconnectioninfo. Wifiinfo contains information about the current connection. // Getbssid () Get bssid attributes // getdetailedstateof () Get client connectivity // gethiddenssid () Get SSID hidden // getipaddress () Get IP address // getlinkspeed () get the connection speed // getmacaddress () Get the MAC address // getarg () Get the signal of the 802.11n network // getssid () Get the SSID // getsupplicanstate () obtain the status information of a specific client. stringbuffer sb = new stringbuffer (); sb. append ("\ n get bssid attribute (MAC address of the connected WiFi device):" + wifiinfo. getbssid (); // sb. append ("getdetailedstateof () to obtain client Connectivity:"); sb. append ("\ n to obtain whether the SSID is hidden:" + wifiinfo. gethiddenssid (); sb. append ("\ n get IP Address:" + wifiinfo. getipaddress (); sb. append ("\ n get connection speed:" + wifiinfo. getlinkspeed (); sb. append ("\ n get MAC address (MAC address of the phone's network adapter):" + wifimac); sb. append ("\ n gets the signal of the 802.11n Network:" + wifiinfo. getarg (); sb. append ("\ n get the SSID (the Network Name of the connected WiFi):" + wifiinfo. getssid (); sb. append ("\ n to obtain information about the specific client status:" + wifiinfo. getsupplicantstate (); Mac. settext ("WiFi network information:" + sb. tostring () + "\ n Bluetooth Mac:" + btmac );}}

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.