最近需要加快wifi的扫描速度,所以使用了Iwlist和Iwconfig这两个工具。下载自:https ://github.com/nvamelichev/wireless-tools-android
编译后,我将这两个二进制文件以适当的权限放入 /system/xbin/。它在“终端模拟器”的应用程序上运行良好,但是当我尝试在我自己的应用程序中执行它们时。它不起作用....这是我的代码:
iwProcess = Runtime.getRuntime().exec("iwlist --version");
BufferedReader reader = new BufferedReader(new InputStreamReader(
iwProcess.getInputStream()));
int read;
char[] buffer = new char[4096];
StringBuffer output = new StringBuffer();
while ((read = reader.read(buffer)) > 0) {
output.append(buffer, 0, read);
}
reader.close();
iwProcess.waitFor();
String nativeOutput = output.toString();
mTextView.setText(nativeOutput);
StringBuffer sb = new StringBuffer();
BufferedReader br = new BufferedReader(new InputStreamReader(
iwProcess.getErrorStream()));
while ((read = br.read(buffer)) > 0) {
sb.append(buffer, 0, read);
}
br.close();
mTextView.setText(output + sb.toString());
结果是“协议不支持的套接字地址系列”真的让我感到困惑......