01.public boolean isWifiConnect() {
02. ConnectivityManager connManager = (ConnectivityManager) getSystemService(CONNECTIVITY_SERVICE);
03. NetworkInfo mWifi = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
04. return mWifi.isConnected();
05. }
代码非常简单,操作也非常简单。
01.boolean isConnected;
02.isConnected = isWifiConnect();
03.if (isConnected == false) {
04.Toast toast = Toast.makeText(Sync.this, "Wifi is NOT connected yet", Toast.LENGTH_SHORT);
05.toast.setGravity(Gravity.CENTER, 0, 0);
06.toast.show();
07.} else {
08.Toast toast = Toast.makeText(Sync.this, "Wifi is connected yet", Toast.LENGTH_SHORT);
09.toast.setGravity(Gravity.CENTER, 0, 0);
10.toast.show();
11.}