I'm using Android with Api level 8 and I want to get the Address of my Ethernet interface (eth0).
On API level 8, the NetworkInterface class don't have the function getHardwareAddress(). The WifiManager also does not work since this is not an Wireless interface.
Thanks in advance!
This is my solution based on the Joel F answer. Hope it helps someone!
/*
* Load file content to String
*/
public static String loadFileAsString(String filePath) throws java.io.IOException{
StringBuffer fileData = new StringBuffer(1000);
BufferedReader reader = new BufferedReader(new FileReader(filePath));
char[] buf = new char[1024];
int numRead=0;
while((numRead=reader.read(buf)) != -1){
String readData = String.valueOf(buf, 0, numRead);
fileData.append(readData);
}
reader.close();
return fileData.toString();
}
/*
* Get the STB MacAddress
*/
public String getMacAddress(){
try {
return loadFileAsString("/sys/class/net/eth0/address")
.toUpperCase().substring(0, 17);
} catch (IOException e) {
e.printStackTrace();
return null;
}
}
Assuming your ethernet interface is eth0, try opening and reading the file /sys/class/net/eth0/address
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With