質問

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