开发者

MAC address of bluetooth or wifi of an android device

I am writing a program about the communication between android device and PC.

Is there any way to get the MAC address of 开发者_StackOverflow社区BLUETOOTH or WiFi of an android device, when the Bluetooth or WiFi is turned OFF?

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.

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!

And to complete the answer.. WiFi state:

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜