문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top