FORUMS
Remove All Ads from XDA

[Question] How to use Tasker to connect and disconnect VPN with "OpenVPN for Android"

53 posts
Thanks Meter: 6
 
By JasMan78, Member on 27th July 2016, 12:55 PM
Post Reply Email Thread
Hi folks,

in the past I used "OpenVPN Connect" to connect to my home network.
I found a guide how I can connect and disconnect the VPN automatically with a Tasker task (e.g. when I'm connected to a unknown wifi).

Now I switched to "OpenVPN for Android" for different reasons. I searched in the Internet for a similar soultion for Tasker, but I didn't found one.
I've managed to set up a task by myself to connect the VPN. But disconnecting doesn't work. aLogcat says "Denied" when I try to call the DisconnectVPN function/class.

I know that there's a app called "OpenVpn Tasker Plugin" which can do this for me. But I'm not a friend of "Apps-for-every-little-task". It would like to solve thiss with the Tasker actions itself.

Here are my tasks:

Connect VPN (works!)
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileName:PROFIL ENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.LaunchVPN
Target:Activity

Disconnect VPN (doesn't work)
Send Intent
Action:android.intent.action.MAIN
Cat:None
Extra:de.blinkt.openvpn.shortcutProfileName:PROFIL ENAME
Package:de.blinkt.openvpn
Class:de.blinkt.openvpn.activities.DisconnectVPN
Target:Activity


The kill action to disconnect the VPN works, but the app restarts the VPN connection itself a few seconds later.

Has anyone an idea how to solve this?

Thank you!
Jas Man
28th July 2016, 10:18 AM |#2  
OP Member
Thanks Meter: 6
 
More
This thread came to the right time
Now I'm working with shell commands (action "Run Shell") to run and stop the VPN.

Start VPN: am start -a android.intent.action.MAIN -n de.blinkt.openvpn/.LaunchVPN -e de.blinkt.openvpn.shortcutProfileName PROFILNAME

Stop VPN: am start -a android.intent.action.MAIN -n de.blinkt.openvpn/activities.DisconnectVPN
(must run with root)

I think the problem with the intents is, that I can't start them with root rights.

Last problem: disconnecting needs a confirmation to stop the VPN. I didn't found any option how I can disable this confirmation. Any idea?
29th July 2016, 05:02 PM |#3  
Member
Thanks Meter: 12
 
More
Disconnecting by bypassing the notification can be done with this xposed plugin

http://repo.xposed.info/module/de.bl...pndialogxposed
30th July 2016, 04:25 PM |#4  
OP Member
Thanks Meter: 6
 
More
Mmmmh, I think this plugin confirmes only the VPN dialog which appeared in Android 4.x ("OpenVPN for Android tries to establish...blablabla").
And this is also a app which I have to install. Then I would prefer the "OpenVPN Tasker" plugin.

But regardless of this, thank you for your post.
31st July 2016, 05:14 AM |#5  
Member
Thanks Meter: 12
 
More
if you want to do purely with Tasker, then I suggest you can also opt for the input tap function
13th August 2016, 05:12 PM |#6  
Junior Member
Thanks Meter: 5
 
More
Quote:

Send Intent
Action: android.intent.action.VIEW
Cat: None
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME: <Your VPN Name>
Package: net.openvpn.openvpn
Class: net.openvpn.openvpn.OpenVPNClient
Target: Activity

for OpenVPN Connect version 1.1.17

I hope this will help you.
The Following User Says Thank You to haode For This Useful Post: [ View ] Gift haode Ad-Free
16th August 2016, 09:09 PM |#7  
OP Member
Thanks Meter: 6
 
More
Quote:
Originally Posted by vickylahkarbytes

if you want to do purely with Tasker, then I suggest you can also opt for the input tap function

That works but only if the screen is not locked. Therefore not usable for me. But also a nice idea.

Quote:
Originally Posted by haode

I hope this will help you.

That works only with "OpenVPN Connect". I use "OpenVPN for Android".
18th August 2016, 09:11 PM |#8  
Senior Member
Thanks Meter: 81
 
More
there is an open vpn tasker plugin the play store that may help you.
20th August 2016, 02:23 PM |#9  
OP Member
Thanks Meter: 6
 
More
Quote:
Originally Posted by HatchetEgg

there is an open vpn tasker plugin the play store that may help you.

At the moment I use this app, but as I wrote in my first post I'm not a friend of "Apps-for-every-little-task". It would like to solve thiss with the Tasker actions itself.
21st August 2017, 11:01 PM |#10  
amplatfus's Avatar
Senior Member
Thanks Meter: 42
 
Donate to Me
More
Hi,

Thank you for all info posted. I have done the connect part. But for disconnect nothing works. I have tried both below solution.
Could you please give a help?
Code:
am start -a android.intent.action.MAIN -net.openvpn.openvpn/activities.DisconnectVPN
and
Code:
Send Intent
Action: android.intent.action.VIEW
Cat: None
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME: <Your VPN Name>
Package: net.openvpn.openvpn
Class: net.openvpn.openvpn.DisconnectVPN
Target: Activity
Thank you!
27th November 2017, 10:06 PM |#11  
Junior Member
Thanks Meter: 1
 
More
Quote:
Originally Posted by amplatfus

Hi,

Thank you for all info posted. I have done the connect part. But for disconnect nothing works. I have tried both below solution.
Could you please give a help?

Code:
am start -a android.intent.action.MAIN -net.openvpn.openvpn/activities.DisconnectVPN
and
Code:
Send Intent
Action: android.intent.action.VIEW
Cat: None
Extra: net.openvpn.openvpn.AUTOSTART_PROFILE_NAME: <Your VPN Name>
Package: net.openvpn.openvpn
Class: net.openvpn.openvpn.DisconnectVPN
Target: Activity
Thank you!



Hello, you can just use the same code that you used to connect the VPN but, replace your VPN name with a bogus name. When it attempts to connect to the bogus VPN it will disconnect from the existing.
The Following User Says Thank You to knightboy09 For This Useful Post: [ View ] Gift knightboy09 Ad-Free
Post Reply Subscribe to Thread

Guest Quick Reply (no urls or BBcode)
Message:
Previous Thread Next Thread
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes