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 ~~~~