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
精彩评论