My project is to make a rear view camera using an old USB webcam and a Raspberry Pi.
I plugged the cam to the pi and using "motion", and I can access the live video with a browser (http://<ip-address>:8081), when I am on the same network as the Pi.
For that, I turned my Pi to a wifi hotspot, in order to be in the same network with my phone to access the video.
But: After I created an application with Android Studio, with a WebView to open the video link, I get a ERR_CONNECTION_REFUSED when mobile data is enabled. Since the Wifi-Network doesn't get used if no internet connection is detected.
I don't want to manually disable it each time I want to use it, I want the application to use the Wi-Fi ONLY.
I managed to auto connect to the pi WiFi using this code :
WifiNetworkSpecifier specifier = new WifiNetworkSpecifier.Builder()
.setSsid("Wifi-Fourcon")
.setWpa2Passphrase("1234567890")
.build();
final NetworkRequest request = new NetworkRequest.Builder()
.addTransportType(NetworkCapabilities.TRANSPORT_WIFI) // we want WiFi
.setNetworkSpecifier(specifier) // we want _our_ network
.build();
ConnectivityManager connectivityManager = (ConnectivityManager)this.getSystemService(CONNECTIVITY_SERVICE);
connectivityManager.requestNetwork(request,
I tried to add
.removeTransportType(NetworkCapabilities.TRANSPORT_CELLULAR)
But same result.
I also tried to disable mobile data with
setMobileDataEnabled()
But we cannot use this method anymore..