2016-03-02 86 views
0

如果Internet連接已啓用,我想檢索MAC地址。 我用下面這段代碼,但它僅適用於無線網絡:Android正在檢索MAC地址

WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
WifiInfo info = manager.getConnectionInfo(); 
String address = info.getMacAddress()); 

我也試試這個,但我在getRuntime得到錯誤:

Process p = Runtime.getRuntime.exec("adb", "shell", "getprop", "ril.wifi_macaddr") 
BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()); 
String macAddress = br.readLine(); 

回答

0

試試這個:

WifiManager manager = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
WifiInfo deviceWifiInfo = manager.getConnectionInfo(); 
String address = deviceWifiInfo.getMacAddress(); 

和添加您的許可AndroidManifest.xml

+0

此代碼的工作原理,但只與WiFi enabled.What我想要獲得MAC地址,即使當我使用eth0或數據連接。 – Rockers23