Android internet connectivity check problem

后端 未结 5 1473
借酒劲吻你
借酒劲吻你 2020-11-28 14:06

I\'m new to Android development and working on an Android application that requires the phone to be connected to the internet, through either Wifi, EDGE or 3G.

This

5条回答
  •  暗喜
    暗喜 (楼主)
    2020-11-28 15:08

    use this to detemine if connceted to wifi/3g:

    is3g = manager.getNetworkInfo(ConnectivityManager.TYPE_MOBILE).isConnected();
        isWifi = manager.getNetworkInfo(ConnectivityManager.TYPE_WIFI).isConnected();
        network = is3g||isWifi;
    

    and this to enable wifi yourself:

    WifiManager wifiManager = (WifiManager) MainWindowYuval.this.getSystemService(Context.WIFI_SERVICE);
                        wifiManager.setWifiEnabled(true);      
    

提交回复
热议问题