Android gets around AP Info

Source: Internet
Author: User

1, increase the authority:

Because this app needs to get the phone's network information, WiFi information, so need to add the relevant permissions in the Androidmanifest.xml file, otherwise it will be reported permission deny error:

1<uses-permissionAndroid:name= "Android.permission.INTERNET"/>2  <uses-permissionAndroid:name= "Android.permission.CHANGE_WIFI_STATE"></uses-permission>    3  <uses-permissionAndroid:name= "Android.permission.ACCESS_WIFI_STATE"></uses-permission>4 <uses-permissionAndroid:name= "Android.permission.ACCESS_NETWORK_STATE"></uses-permission>

2. Get Wifimanager object:

1 wifimanager wm = (Wifimanager) getsystemservice (wifi_service);  // Get WiFi service

Note: Android background runs in many service, they are systemserver on when the system starts, support the system to work properly, Getsystemservice is an important API for Android, Based on the name passed in to obtain the corresponding object, and then converted to the corresponding service object,Getsystemservice is the context of an abstract class method .

3. Start the scan:

1 wm.startscan ();  // initiates a scan. 

Note: This method is returned immediately , should be a new boot thread for the AP scan, so it is best to wait a while (a short time) to obtain the results.

4. Get scan results:

 1  list<scanresult> scanlist = Wmanager.getscanresults ();  2   ( Scanresult scanresult:scanlist) { 3  //   action on scan results  4  String mac = Scanresult.bssid; //  Get the MAC address of the AP  5  String SSID = Scanresult.ssid; //  Get Service Set identity (router name)  6  int  rssi = scanresult.level; // wifi signal strength in dbm  7 } 

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.