| | |
| | | WifiManager wifi = (WifiManager) this.getApplicationContext().getSystemService(Context.WIFI_SERVICE); |
| | | WifiInfo info = wifi.getConnectionInfo(); |
| | | |
| | | try { |
| | | Editor editor = mPre.edit(); |
| | | if (StringUtils.isEmpty(getMacAddress())) { |
| | | editor.putString("mac", info.getMacAddress()); |
| | | } else { |
| | | editor.putString("mac", getMacAddress()); |
| | | } |
| | | editor.commit(); |
| | | } catch (Exception e) { |
| | | |
| | | } |
| | | tv_search = findViewById(R.id.tv_activity_main_search); |
| | | |
| | | iv_msg_dot = findViewById(R.id.iv_msg_dot); |
| | |
| | | EventBus.getDefault().unregister(this); |
| | | } |
| | | |
| | | /* |
| | | * **************************************************************** |
| | | * 子函数:获得本地MAC地址 |
| | | * **************************************************************** |
| | | */ |
| | | private String getMacAddress() { |
| | | String result = ""; |
| | | String Mac = ""; |
| | | result = callCmd("busybox ifconfig", "HWaddr"); |
| | | |
| | | // 如果返回的result == null,则说明网络不可取 |
| | | if (result == null) { |
| | | return "网络出错,请检查网络"; |
| | | } |
| | | |
| | | // 对该行数据进行解析 |
| | | // 例如:eth0 Link encap:Ethernet HWaddr 00:16:E8:3E:DF:67 |
| | | if (result.length() > 0 && result.contains("HWaddr") == true) { |
| | | Mac = result.substring(result.indexOf("HWaddr") + 6, |
| | | result.length() - 1); |
| | | if (Mac.length() > 1) { |
| | | Mac = Mac.replaceAll(" ", ""); |
| | | result = ""; |
| | | String[] tmp = Mac.split(":"); |
| | | for (int i = 0; i < tmp.length; ++i) { |
| | | result += tmp[i]; |
| | | } |
| | | } |
| | | } |
| | | return result; |
| | | } |
| | | |
| | | private String callCmd(String cmd, String filter) { |
| | | String result = ""; |