/** * Gets the MAC address of the device * * @param AC * @param callback * After successfully acquiring the MAC address, this method is recalled */public static void Getmacaddress (final Activity AC, Final Simplecallback callback) {final Wifimanager wm = (Wifimanager) AC. Getsystemservice (Service.wifi_servi (CE)//If WiFi is turned on after the boot, the MAC information can be obtained directly. return data immediately. Wifiinfo info = wm.getconnectioninfo (); if (info! = null && info.getmacaddress () = null) {if (callback! = null) {C Allback.oncomplete (Info.getmacaddress ());} return;} Try to open WiFi and get the MAC address if (!wm.iswifienabled ()) {wm.setwifienabled (true);} New Thread (New Runnable () {@Overridepublic void run () {int trycount = 0;final int max_count = 10;while (Trycount < Max_ COUNT) {Final Wifiinfo info = wm.getconnectioninfo (); if (info! = null && info.getmacaddress () = null) {if (Callba CK = null) {Ac.runonuithread (new Runnable () {@Overridepublic void run () {Callback.oncomplete (info.getmacaddress ());}});} return;} Systemclock.sleep (+); trycount++;} Did not get to MAC address if (callback! = null) {callback.oncomplete (null);}}}). Start ();}
The Simplecallback is a simple callback interface:
public interface Simplecallback {void OnComplete (String result);
Android: A reliable way to get the MAC address of a device