get Mac address by reading /sys/class/net/wlan0/address - Android java.net

Android examples for java.net:Mac Address

Description

get Mac address by reading /sys/class/net/wlan0/address

Demo Code

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;

public class Main {

   static String getMac() {
    String macSerial = "";
    String str = "";
    try {//from  w w w .  jav a2s  .  co m
      Process pp = Runtime.getRuntime().exec("cat /sys/class/net/wlan0/address ");
      InputStreamReader ir = new InputStreamReader(pp.getInputStream());
      LineNumberReader input = new LineNumberReader(ir);

      for (; null != str;) {
        str = input.readLine();
        if (str != null) {
          macSerial = str.trim();
          break;
        }
      }
    } catch (IOException ex) {

      ex.printStackTrace();
    }
    return macSerial;
  }

}

Related Tutorials