简体   繁体   中英

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.

您可以通过在模拟器中按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. 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.

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. That is , switch of the Ethernet connectivity or Wi-fi . Worked well for me.

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