直接上源码
要记得在AndroidManifest.xml中给权限
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
public static String GetLocalMacAddress() {
BluetoothAdapter btAda = BluetoothAdapter.getDefaultAdapter();
//开启蓝牙
if (btAda.isEnabled() == false) {
if (btAda.enable()) {
while (btAda.getState() == BluetoothAdapter.STATE_TURNING_ON
|| btAda.getState() != BluetoothAdapter.STATE_ON) {
try {
Thread.sleep(100);
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
return btAda.getAddress();
}