ConnectivityUtils.java 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /**
  2. * ownCloud Android client application
  3. *
  4. * @author David A. Velasco
  5. * Copyright (C) 2016 ownCloud Inc.
  6. *
  7. * This program is free software: you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2,
  9. * as published by the Free Software Foundation.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  18. */
  19. package com.owncloud.android.utils;
  20. import android.content.Context;
  21. import android.net.ConnectivityManager;
  22. import android.net.NetworkInfo;
  23. import com.owncloud.android.lib.common.utils.Log_OC;
  24. public class ConnectivityUtils {
  25. private final static String TAG = ConnectivityUtils.class.getName();
  26. public static boolean isAppConnectedViaWiFi(Context context) {
  27. ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  28. boolean result =
  29. cm != null && cm.getActiveNetworkInfo() != null
  30. && cm.getActiveNetworkInfo().getType() == ConnectivityManager.TYPE_WIFI
  31. && cm.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED;
  32. Log_OC.d(TAG, "is AppConnectedViaWifi returns " + result);
  33. return result;
  34. }
  35. public static boolean isAppConnected(Context context) {
  36. ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
  37. return cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().isConnected();
  38. }
  39. }