zoukankan      html  css  js  c++  java
  • 获取Mac地址

    private static String getMacByADB() {
    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) {
    return str.trim();// 去空格
    }
    }
    } catch (IOException ex) {
    ex.printStackTrace();
    return "00:00:00:00:00:00";
    }
    return "00:00:00:00:00:00";
    }

    public static String getMacByAPI(Context context) {
    String macAddress = "00:00:00:00:00:00";
    try {
    WifiManager wifiMgr = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
    WifiInfo info = (null == wifiMgr ? null : wifiMgr
    .getConnectionInfo());
    if (null != info) {
    if (!TextUtils.isEmpty(info.getMacAddress())){
    macAddress = info.getMacAddress();
    if (macAddress.equals("02:00:00:00:00:00")) {
    return "00:00:00:00:00:00";
    }
    }
    else
    return macAddress;
    }
    } catch (Exception e) {
    e.printStackTrace();
    return macAddress;
    }
    return macAddress;
    }

    从SharePreferce中获取:getMacinforAddress

    100000次
    getMacinforAddress耗时:434
    getMacByAPI耗时:76213
    getMacByADB耗时:时间太长,没有打印出来

    100次
    getMacinforAddress耗时:28
    getMacByAPI耗时:172
    getMacByADB耗时:2989

    2次
    getMacinforAddress耗时:3
    getMacByAPI耗时:25
    getMacByADB耗时:109

    1次
    getMacinforAddress耗时:0
    getMacByAPI耗时:21
    getMacByADB耗时:141

  • 相关阅读:
    寒假学习5流程控制之ifelse与for循环
    寒假学习4scala数据类型与运算符
    寒假学习13
    寒假学习14
    寒假学习3scala简介与基础1
    sqlserver 定时自动备份
    windows mysql 主从同步
    mysql 连接数 最大并发数
    mysql基础语法
    sqlserver 常见语法
  • 原文地址:https://www.cnblogs.com/shixm/p/5436273.html
Copyright © 2011-2022 走看看