简体   繁体   English

Android设备的蓝牙或wifi的MAC地址

[英]MAC address of bluetooth or wifi of an android device

I am writing a program about the communication between android device and PC. 我正在编写一个关于android设备和PC之间通信的程序。

Is there any way to get the MAC address of BLUETOOTH or WiFi of an android device, when the Bluetooth or WiFi is turned OFF ? 当蓝牙或WiFi 关闭时,有没有办法获取Android设备的BLUETOOTH或WiFi的MAC地址

If so, how? 如果是这样,怎么样?

this works for me with wifi on and off i not try the bluetooth 这对我来说无线开关我不尝试蓝牙

WifiManager wimanager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String address = wimanager.getConnectionInfo().getMacAddress();
Log.d("TOKEN", address);

Yes , you can get MAC addresses even when Bluetooth / WiFi is OFF. 是的 ,即使蓝牙/ WiFi关闭,您也可以获得MAC地址。

Getting bluetooth information is as easy as this: 获取蓝牙信息就像这样简单:

BluetoothAdapter.getDefaultAdapter().getAddress(); // MAC address 
BluetoothAdapter.getDefaultAdapter().isEnabled(); // true if ON 

No need to use Context , yay! 不需要使用Context ,耶!

And to complete the answer.. WiFi state: 并完成答案.. WiFi状态:

final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
wifiManager.getConnectionInfo().getMacAddress(); // MAC address
wifiManager.getWifiState() == WifiManager.WIFI_STATE_ENABLED; // true if ON

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM