//检查网线有没有插
private boolean checkLan(){
Process p=null;
BufferedReader in=null;
try {
p = Runtime.getRuntime().exec("cat /sys/class/net/eth0/carrier");
in = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = null;
String value = "";
while ((line = in.readLine()) != null) {
Log.i("tag", "carrier is "+line);
if("0".equals(line)){
return false;
}
if("1".equals(line)){
return true;
}
}
} catch (Exception e) {
Log.e("tag", e.getMessage());
}
finally{
if(in!=null){
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return false;
}
根据节点的值可以判断网线有没有插入有线网口。