I am trying to check Internet connectivity on Android using the following method. I have a Wi-Fi connection.
private boolean checkInternetConnection() {
To disable the Internet connection, go to Eclipse and do
menu Window -> Show view -> Other -> Android -> Devices
Now select your running emulator and again go to:
menu Window -> Show View -> Other -> Android -> Emulator Control
Now in that... set Data to Unregister from Home.
On the device or in the emulator, go to:
Setting -> Wireless & networks -> Airplane Mode -> OK
telnet localhost 5554
(or Android emulator number)
Internet enabled:
gsm data home
Internet disabled:
gsm data unregistered
You can use my library, available on http://www.cristianmarquez.com.ar.
Steps to disable Internet in the Android emulator:
Now your emulator won't accept an Internet connection.
Note: Here after Airplan mode, you can't install and run your app in the emulator, so before putint it into Airplane mode, run your app in your emulator.
For changing to normal once again, long press emulator and choose the same option.
Try the below command
WIFI:
$ adb shell svc wifi enable
$ adb shell svc wifi disable
MOBILE DATA:
$ adb shell svc data enable
$ adb shell svc data disable
There are many methods. I am explaining two methods here.
Airplane mode Off
It will disconnect your emulator from the Internet. If you want to connect again, just hold on the power button again and select:
Airplane Mode ON
And your emulator's Internet connection will start working!