Android programming Implementation gets the current connection to the WiFi name _android

Source: Internet
Author: User

This article describes the Android programming implementation to get the currently connected WiFi name method. Share to everyone for your reference, specific as follows:

Wifimanager wifimgr = (wifimanager) mactivity.getsystemservice (Context.wifi_service);
 int wifistate = Wifimgr.getwifistate ();
 Wifiinfo info = Wifimgr.getconnectioninfo (); String wifiid = info!= null?
INFO.GETSSID (): null;
 public static inetaddress Getwifiip () {Context mycontext = Globals.getcontext ();
 if (mycontext = = null) {throw new NullPointerException ("Global context is null");
 } Wifimanager wifimgr = (wifimanager) mycontext.getsystemservice (Context.wifi_service);
  if (iswifienabled ()) {int ipasint = Wifimgr.getconnectioninfo (). getipaddress ();
  if (Ipasint = = 0) {return null;
  else {return util.inttoinet (ipasint);
 } else {return null;
}//Get WiFi IP address inetaddress adress = FTPSERVERSERVICE.GETWIFIIP ();
Address.gethostaddress ();
 public static Boolean iswifienabled () {Context mycontext = Globals.getcontext ();
 if (mycontext = = null) {throw new NullPointerException ("Global context is null"); } Wifimanager wifimgr = (wifimanager) mycontext. Getsystemservice (Context.wifi_service); if (wifimgr.getwifistate () = = wifimanager.wifi_state_enabled) {Connectivitymanager Connmanager = (ConnectivityManager
  ) mycontext. Getsystemservice (Context.connectivity_service);
  Networkinfo wifiinfo = Connmanager. Getnetworkinfo (Connectivitymanager.type_wifi);
 return wifiinfo.isconnected ();
 else {return false;
}//Open WIFI Settings page Intent Intent = new Intent (Android.provider.Settings.ACTION_WIFI_SETTINGS);

 StartActivity (Intent);

I hope this article will help you with your Android programming.

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.