0

Is there a way to disconnect any VPN connection on the Android device? My app uses Wi-Fi Direct to establish a P2P connection with other devices. On some devices, Wi-Fi Direct does not work when the VPN is active, and I want to disconnect any VPN connection that is enabled on the device. I tried this code and was able to do so. But using this, the user is asked for permission to access the VPN and then a VPN connection is created with the name of my app. So I do not want to use this code.

startActivityForResult(VpnService.prepare(this), 0);

If there is no way to disconnect, how can the user be redirected to the VPN settings page to do so manually?

Hussein Yaqoobi
  • 442
  • 5
  • 20
  • "Is there a way to disconnect any VPN connection on the Android device?" -- I hope not, except perhaps for device owner apps. "how can the user be redirected to the VPN settings page to do so manually?" -- on API Level 24 and higher, [start an `ACTION_VPN_SETTINGS` activity]( https://developer.android.com/reference/android/provider/Settings#ACTION_VPN_SETTINGS). – CommonsWare Sep 18 '20 at 12:28
  • Thanks CommonsWare. But I think it is possible. Some applications that create a VPN connection first disconnect the previous VPN connection and then establish their own connection. – Hussein Yaqoobi Sep 18 '20 at 12:49
  • Yes, and that is the one valid scenario for it. However, you do not appear to be writing a VPN app. And, you already know how to accomplish that -- it is in your question. You seem to be seeking to have a random other app be able to unilaterally tear down the VPN connection, and that hopefully is not possible except perhaps via device owner (or I guess device admin) apps. – CommonsWare Sep 18 '20 at 13:13

0 Answers0