最近我需要加快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());
结果是“套接字地址系列不受协议支持”,这让我很困惑....