- private String getMac() {
- String macSerial = null;
- String str = "";
- try {
- 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;
- }
- //该片段来自于http://www.codesnippet.cn/detail/1112201411245.html
来源: http://www.codesnippet.cn/detail/1112201411245.html