android 读取mac地址
16lz
2021-01-23
阅读更多 android 读取mac地址,有两种方式:
1.
要留意需要下边的Permission
2.
1.
public String macAddress=null; public void getWifiMacAddress(Context context) { final WifiManager wifi=(WifiManager)c.getSystemService(Context.WIFI_SERVICE); if(wifi==null) return; WifiInfo info=wifi.getConnectionInfo(); this.macAddress=info.getMacAddress(); if(this.macAddress==null && !wifi.isWifiEnabled()) { new Thread() { @Override public void run() { wifi.setWifiEnabled(true); for(int i=0;i<10;i++) { WifiInfo _info=wifi.getConnectionInfo(); macAddress=_info.getMacAddress(); if(macAddress!=null) break; Thread.sleep(500); } wifi.setWifiEnabled(false); } }.start(); }}
要留意需要下边的Permission
2.
/* * Load file content to String */public static String loadFileAsString(String filePath) throws java.io.IOException{ StringBuffer fileData = new StringBuffer(1000); BufferedReader reader = new BufferedReader(new FileReader(filePath)); char[] buf = new char[1024]; int numRead=0; while((numRead=reader.read(buf)) != -1){ String readData = String.valueOf(buf, 0, numRead); fileData.append(readData); } reader.close(); return fileData.toString();} /* * Get the STB MacAddress */public String getMacAddress(){ try { return loadFileAsString("/sys/class/net/eth0/address") .toUpperCase().substring(0, 17); } catch (IOException e) { e.printStackTrace(); return null; }}
更多相关文章
- Android最新资源官方下载地址
- Android_linux下android platforms下载地址
- 通过WifiManager,DhcpInfo获取android IP地址及网关等信息(两种
- Android进阶(一)几种网络请求方式详解
随机推荐
- Android兼容性优化-8.0之后禁止在后台启
- [Android5.1]ContentProvider的Binder通
- 融云清空历史消息 Android(安卓)端
- Android(安卓)Telephony分析(四) ---- Te
- Android(安卓)开发入门-常用控件的使用方
- Kotlin Android(安卓)Extensions 的未来
- Android原生方法和Web JS互相调用
- (Androidx)error: expected reference but
- 待学习 Android(安卓)Building Multi-Lan
- Android(安卓)Studio 4.1 中 Design Tool