Recently I wanted to get a grip on programming for Android. While I was getting through this tutorial: https://dev.to/medaymentn/creating-a-realtime-chat-app-with-android--nodejs-and-socketio-4o55 it turned out that for Android 9 (API level 28) I couldn't connect to my local nodejs server from android device emulator. If I just change all build dependencies to use lower API levels (<=27) it connects correctly. From what i've read on the behavior changes for Android 9 I don't really know what could cause such a thing. Here is the code that is critical i think.
public class ChatBoxActivity extends AppCompatActivity {
//declare socket object
private Socket socket;
public String Nickname;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_chat_box);
// get the nickame of the user
Nickname = (String) getIntent().getExtras().getString(MainActivity.NICKNAME);
//connect you socket client to the server
try {
socket = IO.socket("http://192.168.2.106:3000");
socket.connect();
socket.emit("join", Nickname);
} catch (URISyntaxException e) {
e.printStackTrace();
}
}
}