How to programmatically create a new VPN interface with Android 4.0?

It appears that this is handled internally via the com.android.settings.vpn2.VpnDialog (and related) classes, which basically do KeyStore.getInstance().put(“VPN_[VPN ID]”, [encoded VpnProfile object]>) — which then causes files with names like “/data/misc/vpn/1000_VPN_[VPN ID]” to get created (where 1000 is apparently the system process ID). Using reflection (or one of the hacks to access the hidden / internal … Read more

Check if a VPN connection is active in Android?

Using NetworkCapabilities worked for me. You have to loop over all existing networks and check which has VPN_TRANSPORT ConnectivityManager cm = (ConnectivityManager)mContext.getSystemService(Context.CONNECTIVITY_SERVICE); Network[] networks = cm.getAllNetworks(); Log.i(TAG, “Network count: ” + networks.length); for(int i = 0; i < networks.length; i++) { NetworkCapabilities caps = cm.getNetworkCapabilities(networks[i]); Log.i(TAG, “Network ” + i + “: ” + networks[i].toString()); … Read more