Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VPN connection from Android emulator fails

I am new to Android development. I am trying to join an existing VPN from my Android app. I want to integrate the VPN in my app; my app then is supposed to query a remote database.

I got some code and tried to use it to create a VPN. It emulates the built-in VPN manager on the Android phone. The code compiles and the manager is launched but the connection to the VPN does not succeed when I try to connect after all configuration. The protocol is PPTP. A VPN exists and has been tested.

I tried connecting from an android phone with the same settings and it was successful.

I thought maybe I am passing the parameters in the wrong way. I have put the code for the vpn part below. The url is not the actual but in same format.

Any help to identify what I am doing wrong would be appreciated. Also if there is a way I can directly call the VPN manager from my app.

Thanks very much for any help,


final Button button1 = (Button)findViewById(R.id.button1);
final Button button2 = (Button)findViewById(R.id.button2);
final Button button3 = (Button)findViewById(R.id.button3);


    button1.setOnClickListener(new View.OnClickListener() {
                            public void onClick(View v) {
            startActivity(new Intent("android.net.vpn.SETTINGS"));
        }
    });

    button2.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            URL url = null;
            try {
                String registrationUrl = String.format("daffy.zune.org");
                url = new URL(registrationUrl);
                URLConnection connection = url.openConnection();
                HttpURLConnection httpConnection = (HttpURLConnection) connection;
                int responseCode = httpConnection.getResponseCode();
                if (responseCode == HttpURLConnection.HTTP_OK) {
                    Log.d("MyApp", "Registration success");
                } else {
                    Log.w("MyApp", "Registration failed for: " + registrationUrl);              
                }
            } catch (Exception ex) {
                ex.printStackTrace();
            }

        }
    });
    button3.setOnClickListener(new View.OnClickListener() {
        public void onClick(View v) {
            setContentView(R.layout.register);
        }
    });
    }
}
like image 324
electric_sheep Avatar asked Jun 04 '11 03:06

electric_sheep


People also ask

Can I use VPN in Android emulator?

Or, you can download the VPN app for Android directly onto BlueStacks from the Google Play Store and connect from the emulator itself. Remember that by connecting to the VPN with BlueStacks, the rest of your computer will not be protected by the VPN connection.

Does Bluestack support VPN?

In short, Yes. As with any application running on your PC, BlueStacks will work with a VPN. Once you've connected to the server/country you want, fire up BlueStacks and you'll be able to browse all the content available in that region.


1 Answers

I suggest you look at the simplevpn project and browse the source here and view ShowAllVPNsActivity.java.

Hope this helps! We need more good VPN apps in the Market!

like image 111
vladikoff Avatar answered Oct 04 '22 21:10

vladikoff