Is there a way to get notified when a VPN is connected or disconnected? Because of what I see, the ConnectivityManager does not broadcast any intent about that.
I also tried (unsuccessfully) to register to the hidden ACTION_VPN_CONNECTIVITY broadcast (as seen in android.net.vpn.VpnManager.java source code):
context.registerReceiver(new BroadcastReceiver() { public void onReceive(Context context, Intent intent) { android.util.Log.d("MyApp", "Received VPN broadcast."); } }, new IntentFilter("vpn.connectivity")); // VpnManager.ACTION_VPN_CONNECTIVITY
So is there a way to detect if a VPN is connected, beside polling the networks interfaces periodically to detect the creation of a new network interface (usually ppp0)?
Best regards, David
If your VPN software is not working properly, you can do several things: check your network settings, change your server, make sure the right ports are opened, disable the firewall, and reinstall your VPN software. If none of the below methods are working, it's time to contact your VPN provider.
This can happen if the network has some type of security protocol incompatible with the VPN. It is also possible that the VPN is not configured properly. This can happen if you are using the wrong settings or if the VPN is not set up to work with the specific type of network that you are using.
Reboot and try again. If the IP address is from another country, but not the one you selected, your VPN may be at fault. Close and restart your client, connect to several servers and verify their location with the iplocation.net (opens in new tab) site. Report any variations to your VPN.
sgs2 and emulator worked with:
getApplicationContext().registerReceiver(new BroadcastReceiver()
{
public void onReceive(Context context, Intent intent)
{
logger.Log("VPN broadcast "+context.toString()+": ["+intent.toString()+"]");
}
}, new IntentFilter("vpn.connectivity"));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With