0

I have a VPN service in android where if a user clicks on the SSID of captive portal from his/her WiFi settings and asked to sign in to access internet, I should identify if the user is trying to connect to captive portal, once identification is done, I should disable my vpn service, sign in (or any other authentication required) to connect to captive portal and on successful connection, enable my vpn service again. How can I achieve this in android?

Approach I could think of is using Network Capability in Android :

// Get the current network
ConnectivityManager connectivityManager = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
Network network = connectivityManager.getActiveNetwork();

// Get the network capabilities
NetworkCapabilities networkCapabilities = connectivityManager.getNetworkCapabilities(network);

// Check if the network has a captive portal
if (networkCapabilities.hasCapability(NetworkCapabilities.NET_CAPABILITY_CAPTIVE_PORTAL)) {
    // The network has a captive portal
    // Send event to disable my vpn
} 

But in my case, network capability is not showing CAPTIVE_PORTAL.

0 Answers0