简体   繁体   English

在Android模拟器中以“飞机”模式进行测试

[英]Testing in “Airplane” mode in Android Emulator

I'm trying to test my application for situations when the phone has no connection to the internet. 我正在尝试测试我的应用程序,因为手机没有连接到互联网。

In my emulator, I turned on Airplane Mode in the settings. 在我的模拟器中,我在设置中打开了飞行模式。 However, my app still seemed to be able to communicate with my server. 但是,我的应用程序似乎仍然可以与我的服务器通信。 It works as normal. 它正常工作。

On my device, the same code throws an error with no data connection. 在我的设备上,相同的代码抛出错误,没有数据连接。

How can I ensure that there is no internet connection in the emulator so I can use LogCat etc to analyze the code. 如何确保模拟器中没有互联网连接,以便我可以使用LogCat等来分析代码。

您可以通过在模拟器中按F8关闭Internet访问

In emulator the airplane mode option doesn't works well. 在模拟器中,飞行模式选项不起作用。 so, try pressing F8 function key to stop the internet access to the emulator and check your app in offline. 所以,尝试按F8功能键停止互联网访问模拟器并离线检查您的应用程序。 The airplane mode is closely related the communication signal which has effect only in device but not in emulator. 飞行模式与通信信号密切相关,通信信号仅在设备中有效,但在仿真器中无效。 Anyhow when airplane mode is turned on, automatically the internet access should be stopped, which happening in device but not in emulator. 无论如何,当飞机模式打开时,应自动停止互联网访问,这种情况发生在设备中但不在模拟器中。 Don't worry about that you have an alternative to stop net access by pressing F8. 不要担心您可以通过按F8来停止网络访问。

Then check for network availability through code, enjoy !! 然后通过代码检查网络可用性,享受!!

Instead of using Airplane mode in the Android emulator ( which does not work too well ) , switch off the network connectivity to your system while testing. 不要在Android模拟器中使用飞行模式(效果不佳),在测试时关闭与系统的网络连接。 That is , switch of the Ethernet connectivity or Wi-fi . 也就是说,切换以太网连接或Wi-Fi。 Worked well for me. 对我来说工作得很好。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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