Android obtains information about devices connected to mobile phone hotspots.

Source: Internet
Author: User

I recently developed a project and encountered a problem. When the hotspot is enabled on the mobile phone, I want to find out which device is connected to the hotspot enabled on the android phone.

After google and baidu, no answer was found.

Finally, I remembered that I downloaded an AP Demo in a Foreign Forum, looked at the source code, and finally found a solution to the problem.

As follows: This method must be familiar with the ideas of linux developers. Use the re File Manager to go to "/proc/net/arp, the device information of the hotspot is found here, including the mac ip address.

Private ArrayList <String> getConnectedIP (){
ArrayList <String> connectedIP = new ArrayList <String> ();
Try {
BufferedReader br = new BufferedReader (new FileReader (
"/Proc/net/arp "));
String line;
While (line = br. readLine ())! = Null ){
String [] splitted = line. split ("+ ");
If (splitted! = Null & splitted. length> = 4 ){
String ip = splitted [0];
ConnectedIP. add (ip );
}
}
} Catch (Exception e ){
E. printStackTrace ();
}
Return connectedIP;
}

 

 

Call method:

ArrayList <String> connectedIP = getConnectedIP ();
ResultList = new StringBuilder ();
For (String ip: connectedIP ){
ResultList. append (ip );
ResultList. append ("\ n ");
}
System. out. print (resultList );


Over ~~~~

 


 

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.