No connection with VPN?

Is there a way to get notified when a VPN is connected or disconnected ? Due to what I see, ConnectivityManager does not convey any intentions about it.

I also tried (unsuccessfully) to register for the ACTION_VPN_CONNECTIVITY covert broadcast (as seen from the source code of android.net.vpn.VpnManager.java):

  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 determine if a VPN is connected, in addition to periodically polling network interfaces, in order to detect the creation of a new network interface (usually ppp0)?

Regards, David

+7
source share
3 answers

sgs2 and the 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")); 
+1
source

I tried listening to the "vpn.connectivity" event you mentioned, and it really worked on my Nexus One (Android 2.3.3). I do not know if this matters, but I registered the receiver in the manifest, and not at runtime.

0
source

You should use this example:

  <service android:name=".ExampleVpnService" android:permission="android.permission.BIND_VPN_SERVICE"> <intent-filter> <action android:name="android.net.VpnService"/> </intent-filter> 

0
source

All Articles