I am attempting to stream an IP camera through the Wi-Fi network on my Android version 9 device. However, the Wi-Fi network I am connected to does not provide internet access. I need to use the 4G network for internet access. Everything works fine whenever I turn off 4G and try to access the IP camera. However, when I turn on 4G, I am unable to access the IP camera. I am using libvlc library for accessing the IP camera. And, the camera uses RTSP protocol for streaming.
I tried using ConnectivityManager APIs of Android to select Wi-Fi for the network communication in my app. This didn't work below is the code.
private void SetWifiForInternet() {
ConnectivityManager connectivityManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkRequest.Builder builder = new NetworkRequest.Builder();
builder.addCapability(NetworkCapabilities.NET_CAPABILITY_SUPL);
connectivityManager.requestNetwork(builder.build(), new ConnectivityManager.NetworkCallback() {
@Override
public void onAvailable(Network network) {
super.onAvailable(network);
// Check Android version for binding
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
connectivityManager.bindProcessToNetwork(network);
}
}
});
}