I read a number of examples through this website, but none of them worked on emulator. Sharing the posts I read:
- How to determine Android internet connection?;
- android: how to know internet connection is available or not in device ?;
- how to turn internet connection (GPRS/EDGE/3G) on/off;
- Android Application: Got Internet Connection;
- How find Internet connection is available or not on Android 4G?.
Just to clarify, when I turn off the PC network connection, the emulator still retur开发者_运维问答ns true
.
When you turn off the PC's network connection, the emulator still has one - however it goes no further than the PC.
If you want to determine if it's possible to reach the outside world, you will probably have to try contacting something on the public Internet and seeing that you can both resolve the domain name and actually get traffic there and back.
I can't help wondering why this is important. The emulator is only for testing. If you want to simulate a lack of network connection on the emulator, put it in airplane mode or change its settings. Pulling the PC network connection is comparable to some sort of upstream failure in the mobile provider's infrastructure, not comparable to a device which has neither a mobile nor wifi connection.
精彩评论