如何为 Android 模拟器设置 Internet 选项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/2437366/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 05:51:15  来源:igfitidea点击:

How to set Internet options for Android emulator?

androidandroid-emulator

提问by teepusink

I've been using this method to gain access to internet from my Android emulator emulator -http-proxy <<proxy-name>> -avd <<avd_name>>

我一直在使用这种方法从我的 Android 模拟器 模拟器 访问互联网 -http-proxy <<proxy-name>> -avd <<avd_name>>

It works but is that the best way to do it? It just doesn't feel right that I need to open the emulator from command line and can't just do it from Eclipse or something.

它有效,但这是最好的方法吗?我需要从命令行打开模拟器并且不能从 Eclipse 或其他东西中打开它,这感觉不对。

Can't seem to find an internet option on the "AVD Manager" either.

似乎也无法在“AVD 管理器”上找到 Internet 选项。

回答by Mark McLaren

You could also try explicitly specifying DNS server settings, this worked for me.

您也可以尝试明确指定 DNS 服务器设置,这对我有用。

In Eclipse:

在日食中:

Window>Preferences>Android>Launch

窗口>首选项>Android>启动

Default emulator options: -dns-server 8.8.8.8,8.8.4.4

默认模拟器选项:-dns-server 8.8.8.8,8.8.4.4

回答by Dimitar Dimitrov

By default, you should be able to toggle the Internet access to your emulator with F8 (on Windows) and Fn + F8 (on Mac OS X) - I think F8 also works for Linux, but I'm not 100% sure.

默认情况下,您应该能够使用 F8(在 Windows 上)和 Fn + F8(在 Mac OS X 上)切换对模拟器的 Internet 访问 - 我认为 F8 也适用于 Linux,但我不是 100% 确定。

With this shortcut, you get the ACTION_BACKGROUND_DATA_SETTING_CHANGED dispatched.

使用此快捷方式,您可以发送ACTION_BACKGROUND_DATA_SETTING_CHANGED

Hope that helps.

希望有帮助。

回答by f4bo

for the records since this is an old post and since nobody mentioned it, check if you forgot (as I did) to set the android.permission.INTERNET flag in AndroidManifest.xml as, i.e.:

对于记录,因为这是一个旧帖子并且没有人提到它,请检查您是否忘记(像我一样)将 AndroidManifest.xml 中的 android.permission.INTERNET 标志设置为,即:

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.google.android.webviewdemo">
<uses-permission android:name="android.permission.INTERNET"/>
    <application android:icon="@drawable/icon">
        <activity android:name=".WebViewDemo" android:label="@string/app_name">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest> 

回答by chenjian

-http-proxy can be set in eclipse this way:

-http-proxy 可以通过这种方式在 eclipse 中设置:

  1. Menu Window
  2. Submenu Preferences
  3. In Preferences Dialog Click Android in left part Click Launch Near Default Emulator Options: input ur -http-proxy
  1. 菜单窗口
  2. 子菜单首选项
  3. 在首选项对话框中单击左侧的 Android 单击启动近默认模拟器选项:输入 ur -http-proxy

回答by Akaash Garg

Add GSM Modem Support while creating AVD in your virtual devices from Android SDK and AVD Manager...

通过 Android SDK 和 AVD Manager 在虚拟设备中创建 AVD 时添加 GSM 调制解调器支持...

回答by Antioch

It was setting the DNS that did the trick for me. If you are using the Eclipse or Netbeans plugins, you can set it through Default Emulator options, or Emulator Options respectively. You can also use set it from the command line if you start your emulator from CLI. In all cases, the option is "-dns-server x.x.x.x,x.x.x.x" without the quotes. There is no option in the ADB gui to permanently associate the option with your virtual device.

设置 DNS 对我有用。如果您使用的是 Eclipse 或 Netbeans 插件,则可以分别通过默认模拟器选项或模拟器选项进行设置。如果从 CLI 启动模拟器,也可以从命令行使用 set it。在所有情况下,选项都是不带引号的“-dns-server xxxx,xxxx”。ADB gui 中没有选项可以将该选项与您的虚拟设备永久关联。

回答by sravan

Hi me also faced same issue , solved using below steps:

嗨,我也遇到了同样的问题,使用以下步骤解决:

cause 1:

原因1:

Add internet permission in your android application

在您的 android 应用程序中添加互联网权限

cause 2:

原因2:

Check the manually your default application is able access internet or not if not its problem of your emulator , check in your internet connection in your pc

手动检查您的默认应用程序是否可以访问互联网,如果不是您的模拟器问题,请检查您电脑中的互联网连接

try below method to connect net in your pc

尝试以下方法在您的电脑中连接网络

try explicitly specifying DNS server settings, this worked for me.

尝试明确指定 DNS 服务器设置,这对我有用。

In Eclipse:

在日食中:

Window>Preferences>Android>Launch

窗口>首选项>Android>启动

Default emulator options: -dns-server 8.8.8.8,8.8.4.4**

默认模拟器选项:-dns-server 8.8.8.8,8.8.4.4**

cause 3:

原因3:

check : check if you are using more than one internet connection to your pc like one is LAN second one is Modem , so disable all lan or modem .

检查:检查您是否使用多个互联网连接到您的电脑,例如一个是 LAN,第二个是调制解调器,因此禁用所有 LAN 或调制解调器。

回答by Sree Rama

delete the existing one and recreate the emulator. The machine(windows/mac) should have internet access,and android emulator gets internet access by default.

删除现有的并重新创建模拟器。机器(windows/mac)应该可以上网,android模拟器默认可以上网。

回答by syp_dino

If someone have a Internet Permission in AndroidManifest and still have a problem with Internet Connection, maybe that will be helpful: Android - Fixing the no internet connection issue on emulator.

如果有人在 AndroidManifest 中拥有 Internet 权限,但 Internet 连接仍然存在问题,也许这会有所帮助: Android - 修复模拟器上没有 Internet 连接的问题。

I followed steps from that website, and everything works for me. The most important:

我按照该网站的步骤操作,一切都对我有用。最重要的:

  • Configuring the proxy server on the emulator
  • Incorrect DNS Used by the Emulator
  • 在模拟器上配置代理服务器
  • 模拟器使用的 DNS 不正确

That is my first post, so I hope it will be helpful.

这是我的第一篇文章,所以我希望它会有所帮助。

回答by cdated

On a slightly different note, I had to make a virtual device without GSM Modem Supportso that the internet on my emulator would work.

稍微不同的是,我必须制作一个没有 GSM 调制解调器支持的虚拟设备这样我的模拟器上的互联网才能正常工作。