Tool classes related to WiFi operations

Source: Internet
Author: User
Tags bssid

tool classes related to WiFi operations

Package Com.flyou.utils;import Java.util.list;import Android.content.context;import Android.net.connectivitymanager;import Android.net.networkinfo;import Android.net.wifi.scanresult;import Android.net.wifi.wifiinfo;import Android.net.wifi.wifimanager;import Android.telephony.telephonymanager;public Class Wifiutil {/** * description: Open wifi. * @param context * @param enabled * @return */public static void setwifienabled (Contex T Context,boolean enabled) {Wifimanager Wifimanager = (wifimanager) context.getsystemservice (context.wifi_service); if (enabled) {wifimanager.setwifienabled (true);} Else{wifimanager.setwifienabled (FALSE);}} /** * Description: Whether there is an Internet connection. * @param context * @return */public static Boolean isconnectivity (context context) {Connectivitymanager Connectivitymanag ER = (connectivitymanager) context.getsystemservice (Context.connectivity_service); Telephonymanager Telephonymanager = (telephonymanager) context.getsystemservice (Context.telephony_service); return ( (Connectivitymanager.getactivenetworkiNFO ()! = null && connectivitymanager.getactivenetworkinfo (). GetState () = = NetworkInfo.State.CONNECTED) | | Telephonymanager.getnetworktype () = = Telephonymanager.network_type_umts);} /** * Determine if the current network is a WiFi network. * * @param context The context * @return Boolean */public static Boolean iswificonnectivity (context context) {Connectivity Manager Connectivitymanager = (connectivitymanager) context.getsystemservice (Context.connectivity_service); Networkinfo activenetinfo = Connectivitymanager.getactivenetworkinfo (); if (activenetinfo! = null&& Activenetinfo.gettype () = = Connectivitymanager.type_wifi) {return true;} return false;} /** * Description: Get all the WiFi listings. * @param context * @return */public static list<scanresult> getscanresults (context context) {Wifimanager Wifimanage R = (Wifimanager) context.getsystemservice (Context.wifi_service); List<scanresult> list = null;//begins scanning Wifiboolean f = wifimanager.startscan (); if (!f) {getscanresults (context);} else{//Get scan Result list = Wifimanager.getscanresUlts ();} return list;} /** * Description: Filters scan results based on SSID. * @param context * @param bssid * @return */public static Scanresult getscanresultsbybssid (context context,string bssid) { Wifimanager Wifimanager = (wifimanager) context.getsystemservice (Context.wifi_service); Scanresult Scanresult = null;//starts scanning wifiboolean f = wifimanager.startscan (), if (!f) {Getscanresultsbybssid (context, BSSID);}  Get scan results list<scanresult> list = Wifimanager.getscanresults (), if (list! = null) {for (int i = 0; i < list.size (); i++) {//Get scan result scanresult = List.get (i); if (ScanResult.BSSID.equals (BSSID)) {break;}}} return scanresult;} /** * Description: Get connected WiFi information. * @param context * @return */public static Wifiinfo Getconnectioninfo (context context) {Wifimanager Wifimanager = (wifiman Ager) Context.getsystemservice (Context.wifi_service); Wifiinfo wifiinfo = Wifimanager.getconnectioninfo (); return wifiinfo;}}


Tool classes related to WiFi operations

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.