How to Invoke VPN client ?

777 views
Skip to first unread message

philippe bauchard

unread,
Aug 25, 2015, 2:03:20 PM8/25/15
to AndroidScript
Hi all,

I have  a DS home automation app driving web relay boards.
When I use it from the internet, I use a VPN tunnel with Android PPTP in order to ensure privacy of my commands.

Works fine but as the VPN is not permanently set, I would like to automatically start the VPN client on my device right from my DS app. instead of manually start the vpn client before the app.

Is there a way to do that ?
Using shell comand line with app.CreateSysProc ?
Therefore what would be the command line ?

Best,
Philippe 

Dave Smart

unread,
Aug 26, 2015, 5:53:14 AM8/26/15
to AndroidScript
Hi Philippe,

You might be able to use the app.SendIntent method if you can work out the class names in your target application.  Check out the 'Send Intent' sample to see how it is done.

You can get Apps such as ManifestViewer on Google Play which let you view the manifest of an App and this should allow you to work out the necessary names to put into the app.SendIntent() call (most of the parameters can be left blank apart from packageName and className).

Regards
David

philippe bauchard

unread,
Aug 29, 2015, 5:17:52 PM8/29/15
to AndroidScript
Hi Dave,
Thanks for suggestion.

With Manifestviewer, I found vpndialogs, which apparently is the ad hoc activity to trigger.
I tried the code below.

app.SendIntent("com.android.vpndialogs","com.android.vpndialogs.ManageDialog","","","","","");

However, absolutely nothing is happening. There must be an error. But is theré a way to catch errors after Sendintent ?

Brgds,
Philippe

Dave Smart

unread,
Aug 31, 2015, 4:32:41 AM8/31/15
to AndroidScript
Hi Philippe,

I think you will need to set the action parameter to "android.intent.action.VIEW" or "android.intent.action.MAIN"

Regards
David

philippe bauchard

unread,
Aug 31, 2015, 5:10:27 PM8/31/15
to AndroidScript
Hi Dave,
I have tried both parms in 3rd position of the sendintent call, but still apparently no effect. For sure no menu popping up.

What is a bit frustrating is to be quite blind, not having an error message to work on.

Brgds,
Philippe

Dave Smart

unread,
Sep 2, 2015, 7:28:15 AM9/2/15
to AndroidScript
Is the VPN App free?  What is it called?

philippe bauchard

unread,
Sep 2, 2015, 2:08:39 PM9/2/15
to AndroidScript
Hi Dave,

Not sure to understand correctly your question.

What I am trying to do is to use (precisely trigger automatically the menu) of the  Android standard built-in VPN client (which can be found in the parameters in the "more network" part). I have configured it using PPTP and when opened manually it works fine, I can secure  access to my box. (using addresses 192.168.... of my local network from the internet).

I want to do that so that I can be prompted directly in the DS app with the menu popping up to directly choose the VPN connection among those defined and enter the password and therefore open the tunnel to my internet box and then go back to the app focus.

I did not install a specific app. as VPN.

Here below the test code I used after your advice, which  does not yet provide the expected behaviour.
I am not famliliar with the Android core architecture, so perhaps what I want to do must be addressed completely differently.

The new input however is that if run it from the IDE, I have no message BUT if I generate an APK I get the following message:

Script Error: app.SendIntent is not a function

Thanks for your help.

Device is Galaxy Tab S 8.4 Lollipop. 

Brgds,
Philippe

------------------------
//Called when application is started.
function OnStart()
{
//Create a layout with objects vertically centered.
lay = app.CreateLayout( "linear", "VCenter,FillXY" );

    //Create a button.
    btn = app.CreateButton( "Button", 0.4 );
    btn.SetMargins( 0, 0.02, 0, 0 );
    btn.SetOnTouch( btn_OnTouch );
    lay.AddChild( btn );

//Add layout to app.
app.AddLayout( lay );
}

function btn_OnTouch(  ) 

{

app.SendIntent( "com.android.vpndialogs",
                "com.android.vpndialogs.ManageDialog",
                "android.intent.action.VIEW",
                "","","","");

}

Chris Hopkin

unread,
Sep 3, 2015, 10:41:43 AM9/3/15
to AndroidScript
Hello Philippe

If I understand, you want to show the built in Android VPN Settings (Settings->More networks->VPN)?

According to this post on Stack Overflow it should just be a case of using the Intent action "android.net.vpn.SETTINGS":


The DroidScript SendIntent method requires the packagename and classname at the moment, so it won't work by just specifying the action alone. But I think it would be a useful change if SendIntent supported actions like these.

It may also be possible to show VPN settings using SendIntent right now, but I haven't been able to find out what the packagename or classname should be, perhaps someone else can help? The following will launch the Android Settings at the top level:

app.SendIntent( "com.android.settings",
               
"com.android.settings.Settings",
               
"android.intent.action.VIEW",
               
null,null,null,null);

Regarding SendIntent not working from an APK, your APKBuilder plugin maybe out of date, please try reinstalling it from the Plugins menu and try again.

Thanks

Chris

philippe bauchard

unread,
Sep 3, 2015, 3:11:00 PM9/3/15
to AndroidScript
Hello Chris,

Thank you.

At least, going to the Android settings when tunnel opening is required is a first step.
I will continue to investigate and see if I can find the related classes.

Indeed, it would be handy to have the support of actions like this in a future version.

Brgds,
Philippe

philippe bauchard

unread,
Sep 5, 2015, 2:11:35 AM9/5/15
to AndroidScript
Hi Chris, Dave,

I found on the playstore an app (from Blazasoft) implementing this shortcut to VPN setings.
So the code below does exactly what I want which is to trigger the VPN menu when required:

      app.SendIntent( "com.blazasoft.vpn",
                "com.blazasoft.vpn.MainActivity",
                null,
                null,null,null,null); 

Still it is a workaround and, ideally, I would prefer DS to allow triggering directly such actions.

Brgds,
Philippe
Reply all
Reply to author
Forward
0 new messages