Using the socket class, I want to check the ip address that is currently connected regardless of Wi-Fi or LTE.
try {
Socket mysocket = new Socket("www.google.com", 80);
String Addr = mysocket.getLocalAddress().getHostAddress();
tv8.setText(Addr);
}catch (Exception e){
Log.e("TAG",e.getMessage());
}
The application is forced to terminate when the code is executed, and the log does not appear May I know what the problem is?
java android-studio
MainThread is unable to work with the network.
Make socket communication after creating a separate Thread.
© 2024 OneMinuteCode. All rights reserved.