Android obtains information about devices connected to mobile phone hotspots.

Source: Internet
Author: User

From: http://blog.csdn.net/beijingshi1/article/details/9119297

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.