//檢查網線有沒有插
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;
}
根據節點的值可以判斷網線有沒有插入有線網口。