android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED 备选方案
android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED alternative
我正在尝试实现一种方法来侦听智能手机热点上的客户端连接事件。我看到 android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED 不再可用。我怎样才能做到这一点?我认为这是可能的,因为当我客户端连接到智能手机热点时,智能手机会通知我。
您不能使用 Intent Action...您必须使用自定义方法,我建议您创建一个后台线程 checks/reads I.P table (/proc/net/arp) 不断更新你...这是我用过的片段。
阅读i.p列表table
public ArrayList<String> getConnectedDevices() {
ArrayList<String> arrayList = new ArrayList();
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
String[] split = readLine.split(" +");
if (split != null && split.length >= 4) {
arrayList.add(split[0]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return arrayList;
}
创建可运行的以检查
class CheckHotSpotConnection implements Runnable {
private CheckHotSpotConnection() {
}
public void run() {
int i = 0;
while (discoverClient()) {
i = getConnectedDevices().size();
if (i > 1) {
//client discovered
//disable client discovery to end thread
} else {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
开始话题
new Thread(new CheckHotSpotConnection()).start();
我正在尝试实现一种方法来侦听智能手机热点上的客户端连接事件。我看到 android.net.wifi.WIFI_HOTSPOT_CLIENTS_CHANGED 不再可用。我怎样才能做到这一点?我认为这是可能的,因为当我客户端连接到智能手机热点时,智能手机会通知我。
您不能使用 Intent Action...您必须使用自定义方法,我建议您创建一个后台线程 checks/reads I.P table (/proc/net/arp) 不断更新你...这是我用过的片段。
阅读i.p列表table
public ArrayList<String> getConnectedDevices() {
ArrayList<String> arrayList = new ArrayList();
try {
BufferedReader bufferedReader = new BufferedReader(new FileReader("/proc/net/arp"));
while (true) {
String readLine = bufferedReader.readLine();
if (readLine == null) {
break;
}
String[] split = readLine.split(" +");
if (split != null && split.length >= 4) {
arrayList.add(split[0]);
}
}
} catch (Exception e) {
e.printStackTrace();
}
return arrayList;
}
创建可运行的以检查
class CheckHotSpotConnection implements Runnable {
private CheckHotSpotConnection() {
}
public void run() {
int i = 0;
while (discoverClient()) {
i = getConnectedDevices().size();
if (i > 1) {
//client discovered
//disable client discovery to end thread
} else {
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
}
}
开始话题
new Thread(new CheckHotSpotConnection()).start();