Pergunta

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!..

Foi útil?

Solução

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.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top