I am trying to listen the event when someone connect to/disconnect from my portable AP hotspot. I try this code
Process p;
try
{
p = Runtime.getRuntime().exec("logcat -s hostapd:I");
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = br.readLine()) != null)
{
if (line.contains("AP-STA-CONNECTED") || line.contains("AP-STA-DISCONNECTED")) Log.e("mytag", line);
}
}
catch (IOException e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
and it works like what I want. But I don't know how to put it in my service to run parallel with my activity. Or is there another way to identify when someone connect or disconnect from my portable AP hotspot?