Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;

import android.content.Intent;

import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import android.net.wifi.WifiManager;

public class Main {
    static public boolean isDisconnectedIntent(Intent intent) {
        boolean res = false;
        NetworkInfo networkInfo = (NetworkInfo) intent.getParcelableExtra(ConnectivityManager.EXTRA_NETWORK_INFO);
        if (networkInfo != null) {
            NetworkInfo.State state = networkInfo.getState();
            res = (state.equals(NetworkInfo.State.DISCONNECTING) || state.equals(NetworkInfo.State.DISCONNECTED))
                    && (networkInfo.getType() == ConnectivityManager.TYPE_WIFI);

        } else {
            int wifiState = intent.getIntExtra(WifiManager.EXTRA_WIFI_STATE, WifiManager.WIFI_STATE_UNKNOWN);
            if (wifiState == WifiManager.WIFI_STATE_DISABLED || wifiState == WifiManager.WIFI_STATE_DISABLING) {
                res = true;
            }
        }
        return res;
    }
}