I have a question about android.net.NetworkCapabilities.NET_CAPABILITY_INTERNET
. According to the JavaDocs this "indicates that this network should be able to reach the internet".
Unfortunately this seems not to work properly - or I do something wrong here. I outputed the value of capabilities for three different Wi-Fi networks:
A Wi-Fi with internet access.
A Wi-Fi without internet access (I manually disabled the internet here).
A public hotspot (the "Telekom" hotspot)
In all three cases the capabilities value is [ Transports: WIFI Capabilities: INTERNET&NOT_RESTRICTED&TRUSTED&NOT_VPN LinkUpBandwidth>=1048576Kbps LinkDnBandwidth>=1048576Kbps]
.
This is my code:
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkCapabilities capabilities = connectivityManager.getNetworkCapabilities(network);
boolean capability = capabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET
The boolean value is always true
when connected with some Wi-Fi.
If it is relevant, the device I've tested is running under Android 5.0.1 (API 21). I compiled the app to API level 23.
NO_INTERNET
in case a Wi-Fi does not provide internet. But even if no internet is provided the capabilityINTERNET
is set. – Mediacy