- 获取利用android标准API获取mac地址,注意加权限, <uses-permission android:name="android.permission.INTERNET" />
- /**
- * 读取文件内容
- */
- private void readFileMac() {
- File usbFile = new File("mnt/sda/sda1/kvUpdateMac/usbUpdateMac.txt");
- if (!usbFile.exists()) {
- return;
- }
- FileInputStream inputStream = null;
- try {
- inputStream = new FileInputStream(usbFile);
- byte[] buffer = new byte[inputStream.available()];
- inputStream.read(buffer);
- String hhh = new String(buffer);
- String macthMac = "[0-9A-Fa-f]{12}";
- if (hhh.length() == 12 && hhh.matches(macthMac)) {
- mac = hhh;
- } else {
- mac = "";
- }
- } catch (FileNotFoundException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- } finally {
- try {
- if (inputStream != null) {
- inputStream.close();
- }
- } catch (IOException e) {
- e.printStackTrace();
- }
- }
- }