【问题标题】:VPN connection from Android emulator failsAndroid 模拟器的 VPN 连接失败
【发布时间】:2011-09-08 05:38:42
【问题描述】:

我是 Android 开发的新手。我正在尝试从我的 Android 应用程序加入现有的 VPN。我想在我的应用程序中集成 VPN;然后我的应用程序应该查询远程数据库。

我得到了一些代码并试图用它来创建一个 VPN。它模拟 Android 手机上的内置 VPN 管理器。代码编译并启动管理器,但是当我在所有配置后尝试连接时,与 VPN 的连接没有成功。协议是PPTP。存在 VPN 并且已经过测试。

我尝试从具有相同设置的安卓手机连接,并且成功。

我想也许我以错误的方式传递参数。我已将 vpn 部分的代码放在下面。该网址不是实际的,但格式相同。

任何帮助确定我做错了什么都将不胜感激。此外,如果有办法我可以直接从我的应用程序调用 VPN 管理器。

非常感谢您的帮助,


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);
        }
    });
    }
}

【问题讨论】:

  • 我很困惑。您是否尝试手动连接到 VPN,切换回您的应用程序,然后连接到远程数据库?
  • 我认为您需要确定是否需要建立 HTTPS 或 HTTP 连接,我猜您需要建立 HTTPS 连接才能注册。

标签: android android-emulator vpn


【解决方案1】:

我建议您查看simplevpn 项目并浏览source here 并查看ShowAllVPNsActivity.java

希望这会有所帮助!我们需要市场上更多优秀的 VPN 应用!

【讨论】:

    猜你喜欢
    • 2012-03-23
    • 2011-12-21
    • 1970-01-01
    • 2022-06-28
    • 2015-11-17
    • 2011-08-23
    • 2014-03-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多