1) You can use BroadcastReciever "android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED" to detect client connection.
In your AndroidManifest:
<receiver
android:name=".WiFiConnectionReciever"
android:enabled="true"
android:exported="true" >
<intent-filter>
<action android:name="android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED" />
</intent-filter>
</receiver>
And in Activity:
IntentFilter mIntentFilter = new IntentFilter();
mIntentFilter.addAction("android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED");
rcv = new WiFiConnectionReciever();
registerReceiver(rcv,mIntentFilter);
2) You can also get the list of connected devices to HOTSPOT
public void getConnectedClientList() {
int clientcount = 0;
BufferedReader br = null;
try {
br = new BufferedReader(new FileReader("/proc/net/arp"));
String line;
while ((line = br.readLine()) != null) {
String[] splitted = line.split(" +");
String mac = splitted[3];
System.out.println("Mac : Outside If "+ mac );
if (mac.matches("..:..:..:..:..:..")) {
clientcount++;
System.out.println("Mac : "+ mac + " IP Address : "+splitted[0] );
System.out.println("Client_count " + clientcount + " MAC_ADDRESS "+ mac);
Toast.makeText(
getApplicationContext(),
"Client_count " + clientcount + " MAC_ADDRESS "
+ mac, Toast.LENGTH_SHORT).show();
}
}
} catch(Exception e) {
}
}