package com.cityzen.cityzen.Utils.DeviceUtils; import android.content.Context; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.telephony.TelephonyManager; /** * Created by Valdio Veliu on 06/05/2017. */ public class DeviceUtils { public static boolean isInternetConnected(Context ctx) { ConnectivityManager connectivityMgr = (ConnectivityManager) ctx .getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo wifi = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI); NetworkInfo mobile = connectivityMgr.getNetworkInfo(ConnectivityManager.TYPE_MOBILE); // Check if wifi or mobile network is available or not. If any of them is // available or connected then it will return true, otherwise false; if (wifi != null) { if (wifi.isConnected()) { return true; } } if (mobile != null) { if (mobile.isConnected()) { return true; } } return false; } public static boolean isGPSEnabled(Context mContext) { LocationManager locationManager = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); return locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER); } }