Computer >> Hướng Dẫn Máy Tính >  >> Lập Trình >> Android

Lấy địa chỉ IP của Android Emulator

Dùng WifiManager và Formatter.formatIpAddress:

WifiManager wifi = (WifiManager) getApplicationContext().getSystemService(WIFI_SERVICE);
String ip = Formatter.formatIpAddress(wifi.getConnectionInfo().getIpAddress());
textView.setText("IP Address: " + ip);

Cần permission ACCESS_WIFI_STATE và INTERNET trong Manifest.

Bấm button "Get IP Address" → TextView hiển thị IP của emulator/thiết bị.