我正在编写一款关于安卓设备和电脑之间通信的程序。
在蓝牙或WiFi关闭的情况下,有没有办法获取安卓设备的蓝牙或WiFi的MAC地址?
如果有,该如何操作?
我正在编写一款关于安卓设备和电脑之间通信的程序。
在蓝牙或WiFi关闭的情况下,有没有办法获取安卓设备的蓝牙或WiFi的MAC地址?
如果有,该如何操作?
是的,即使关闭了蓝牙/ WiFi,你仍然可以获取MAC地址。
获取蓝牙信息就像这样简单:
BluetoothAdapter.getDefaultAdapter().getAddress(); // MAC address
BluetoothAdapter.getDefaultAdapter().isEnabled(); // true if ON
不需要使用Context
,太棒了!
为了完整回答.. WiFi状态:
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.getConnectionInfo().getMacAddress(); // MAC address
wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED; // true if ON
02:00:00:00:00:00
。 - zygimantus这对我来说在开启和关闭wifi时都有效,我还没有尝试过蓝牙。
WifiManager wimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String address = wimanager.getConnectionInfo().getMacAddress();
Log.d("TOKEN", address);