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