Пример #1
1
    public void onReceive(Context context, Intent intent) {
      String action = intent.getAction();
      if (action.equals(CONNECTIVITY_CHANGE_ACTION) && NetworkStatusManager.this.mListening) {
        boolean noConnectivity = intent.getBooleanExtra("noConnectivity", false);
        if (noConnectivity) {
          NetworkStatusManager.this.mState = NetworkStatusManager.State.NOT_CONNECTED;
        } else {
          NetworkStatusManager.this.mState = NetworkStatusManager.State.CONNECTED;
        }

        NetworkStatusManager.this.mNetworkInfo = intent.getParcelableExtra("networkInfo");
        NetworkStatusManager.this.mOtherNetworkInfo = intent.getParcelableExtra("otherNetwork");
        NetworkStatusManager.this.mReason = intent.getStringExtra("reason");
        NetworkStatusManager.this.mIsFailOver = intent.getBooleanExtra("isFailover", false);
        Log.d(
            "NetworkStatusManager",
            "onReceive(): mNetworkInfo="
                + NetworkStatusManager.this.mNetworkInfo
                + " mOtherNetworkInfo = "
                + (NetworkStatusManager.this.mOtherNetworkInfo == null
                    ? "[none]"
                    : NetworkStatusManager.this.mOtherNetworkInfo + " noConn=" + noConnectivity)
                + " mState="
                + NetworkStatusManager.this.mState.toString());
        NetworkStatusManager.this.mIsWifi =
            NetworkStatusManager.checkIsWifi(NetworkStatusManager.this.mContext);
      } else {
        Log.w(
            "NetworkStatusManager",
            "onReceived() called with "
                + NetworkStatusManager.this.mState.toString()
                + " and "
                + intent);
      }
    }
Пример #2
0
 @Override
 protected void onDestroy() {
   super.onDestroy();
   NetworkStatusManager.getInstance().stopListening();
 }
Пример #3
0
 public static void init(Context context) {
   sInstance = new NetworkStatusManager();
   sInstance.mIsWifi = checkIsWifi(context);
   sInstance.startListening(context);
 }