您的位置:首页 > 移动开发 > Android开发

获取android设备的MAC地址

2015-08-31 10:14 393 查看
android 底层是 Linux,我们还是用Linux的方法来获取:

1 cpu号:

文件在: /proc/cpuinfo

通过Adb shell 查看:

adb shell cat /proc/cpuinfo

2 mac 地址

文件路径 /sys/class/net/wlan0/address

adb shell cat /sys/class/net/wlan0/address

xx:xx:xx:xx:xx:aa

具体的实现代码为:

public static String getLocalMac() {

String mac=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)

{

mac = str.trim();// 去空格

break;

}

}

} catch (IOException ex) {

// 赋予默认值

ex.printStackTrace();

}

return mac;

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: