简体   繁体   中英

Connect pptp vpn with android vpnservice

I'm trying to write an application that could connect to my VPN server with pptp protocol , as i was researching I found out that with android.net.vpnservice I could connect, but as I read some of documentation it was not clear how to connect to VPN (there were no API to set username or password, and also no API to set my VPN type( l2tp,pptp ); I also tested example application Google provided(toyvpn) and there were none of what I mentioned earlier there too.

Here is some code I found :

// Create a new interface using the builder and save the parameters.
mInterface = builder.setSession(mServerAddress)
                .setConfigureIntent(mConfigureIntent)
                .establish();
mParameters = parameters;

Hi this is a bit late but I have found something while searching.

I am also trying to build my own VPN tunnel / connection with using pptp and openvpn.

OpenVPN already has a solution.

PPTP am trying the solution below.

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

link above was found at

How to configure VPN programmatically?

i was trying the same.

For VPN Service u can do this.

 void startVPN(String name) {
   Intent i=new Intent("doenter.onevpn.ACTION_CONNECT");
   i.putExtra("name",name);
   i.putExtra("force", true); 
   i.putExtra("force_same", false); 
   startActivity(i);
      }

    void restartVPN(String name) {
      Intent i=new Intent("doenter.onevpn.ACTION_CONNECT");
     i.putExtra("name",name);
     i.putExtra("force", true); 
     i.putExtra("force_same", true); 
     startActivity(i);
  }

  void stopVPN() {
   Intent i=new Intent("doenter.onevpn.ACTION_DISCONNECT");
   // Stops any VPN regardless of name
    startActivity(i);
     } 

This Link can help you to get your Answer.

http://doandroids.com/Apps/OneVpn/how-to/start-stop-prgrammatically/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM