android - Getting the MAC address of the device- when wifi is off -
i finding mac address of android device using next code:
wifimanager manager = (wifimanager) getsystemservice(context.wifi_service); wifiinfo info = manager.getconnectioninfo(); string address = info.getmacaddress());
but in case unable mac address when wifi off. how can mac address of android device when wifi off.
thanks
why not enable wifi momentarily until mac address , disable 1 time done getting mac address?
of course, doing if getting mac address absolutely important.
untested code
wifimanager wifimanager = (wifimanager) this.getsystemservice(context.wifi_service); if(wifimanager.iswifienabled()) { // wifi enabled. grab mac address here wifiinfo info = wifimanager.getconnectioninfo(); string address = info.getmacaddress(); } else { // enable wifi first wifimanager.setwifienabled(true); // wifi enabled. grab mac address here wifiinfo info = wifimanager.getconnectioninfo(); string address = info.getmacaddress(); }
you need these permission setup in manifest
<uses-permission android:name="android.permission.access_wifi_state"></uses-permission> <uses-permission android:name="android.permission.update_device_stats"></uses-permission> <uses-permission android:name="android.permission.change_wifi_state"></uses-permission>
i not exclusively sure if update_device_stats
permission necessary in case. please seek out before deciding maintain it.
android android-wifi mac-address wifimanager
No comments:
Post a Comment