xhlwill
xhlwill

Reputation: 399

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 BLUETOOTH or WiFi of an android device, when the Bluetooth or WiFi is turned OFF?

If so, how?

Upvotes: 3

Views: 3378

Answers (2)

Marcel Bro
Marcel Bro

Reputation: 5025

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

Upvotes: 1

ademar111190
ademar111190

Reputation: 14505

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);

Upvotes: 1

Related Questions