How do I disable the Internet connection in Android Emulator?

后端 未结 11 1650
执念已碎
执念已碎 2020-12-29 01:33

I am trying to check Internet connectivity on Android using the following method. I have a Wi-Fi connection.

private boolean checkInternetConnection() {
             


        
相关标签:
11条回答
  • 2020-12-29 01:39

    Android Studio 3.0 Update

    Simply drag and open the control center and click on the airplane mode button as what you are doing on your actual device.

    Please bear with me for a very slow emulator.

    0 讨论(0)
  • 2020-12-29 01:39

    To check on a real device (and also in the emulator), go to:

    Settings > Wireless and Networks > Mobile Networks > Data enabled

    Uncheck it and it will work.

    0 讨论(0)
  • 2020-12-29 01:40

    Recent emulator versions provide an easier way, from an ADT view:

    Window -> Show view -> Other... -> Android -> Emulator Control
    

    Simply change "Data" value from "Telephony Status" and test your application again.

    0 讨论(0)
  • 2020-12-29 01:41

    You can disable the Internet connection by pressing F8 in any Android emulator. It is a toggle button, so if it doesn't have Internet connection then it will start the Internet connection and if it already has an Internet connection then it will dis-connect it.

    0 讨论(0)
  • 2020-12-29 01:47

    You can actually disable internet connection in the simulator just as you would in a real phone.

    1. Swipe down the screen to see the notification panel.
    2. Tap on the data network icon
    3. Turn off the cellular network.

    I just tried it successfully in an android 4.4 image loaded into my simulator.

    0 讨论(0)
  • 2020-12-29 01:47
    public boolean isOnline() {
     ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
     return cm.getActiveNetworkInfo().isConnectedOrConnecting();
    
    }
    
    0 讨论(0)
提交回复
热议问题