Question

Right now i am trying to get mac address for tablets and smartphone in android.

I have tried with the below code.

TelephonyManager tm =   (TelephonyManager)Current_activity_name.this.getSystemService(Context.TELEPHONY_SERVICE); 
String str_macid = tm.getDeviceId();

this code is working only for smartphone but not for tablets.Why?

Suggestions please..

Thanks for your precious time!..

Était-ce utile?

La solution

If you want to get the MAC address of the WiFi modem you first need a permission

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />

Next

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
String macAddress = wifiManager.getConnectionInfo().getMacAddress();

This works if a WiFi connection currently exists.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top