0

I am using the following code to scan the wifi devices connected to my Hotspot enabled device. It is detecting almost all the devices, but the problem is the list is not getting refreshed when the wifi devices are disconnected from the hotspot (i.e the list shows the wifi devices even if they are disconnected,the list is not supposed to show the devices which are disconnected). It shows the wifi device in the list if it is connected once to my hotspot device & the device list is not getting refreshed till the time I dont turn off the hotspot Following is my code snippet...

public ArrayList getClientList(boolean onlyReachables, int reachableTimeout) {

    BufferedReader br = null;
    ArrayList<ClientScanResultSO> result = null;

   try {
        result = new ArrayList<ClientScanResultSO>();
        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)) {
                // Basic sanity check
                String mac = splitted[3];
                System.out.println("mac is***************"+ mac);
                if (mac.matches("..:..:..:..:..:..")) {
                    boolean isReachable = InetAddress.getByName(splitted[0]).isReachable(reachableTimeout);
                    String name = InetAddress.getByName(splitted[0]).getHostName();
                    if (!onlyReachables || isReachable) {
                        result.add(new ClientScanResultSO(splitted[0], splitted[3], splitted[5], isReachable, name));
                    }
                }
            }
        }
    } catch (Exception e) {
        Log.e(this.getClass().toString(), e.getMessage());
    } finally {
        try {
            br.close();
        } catch (IOException e) {
            Log.e(this.getClass().toString(), e.getMessage());
        }
    }

    return result;
}

I want the wifi devices are not to be shown in the list when they are disconnected from my android device which is hotspot enabled Somebody please help me in this regard. Thanks!

Atul Panda
  • 357
  • 5
  • 20

1 Answers1

0

I am not sure about my understanding is correct, i have a concern on the following line of your code String[] splitted = line.split(" +"); Are you using a white space and + symbol for concatenating MAC address's of the devices.

Regards Ajil

Ajil Mohan
  • 7,299
  • 2
  • 18
  • 18
  • "/proc/net/arp" ---This holds an ASCII readable dump of the kernel ARP table used for address resolutions. It will show both dynamically learned and pre-programmed ARP entries. The format is: "IP address" "HW type" "Flags" "HW address" "Mask" "Device"....to separate these thing i am using split – Atul Panda Sep 21 '12 at 13:48