Back to project page Common-Library.
The source code is released under:
Apache License
If you think the Android project Common-Library listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.morgan.library.utils; /*from w w w. j a va 2 s . c om*/ import android.content.Context; import android.content.Intent; import android.location.LocationManager; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.provider.Settings; import com.morgan.library.app.APPContext; /** * ?????????????? * * @author Morgan.Ji * */ public class NetUtils { public static boolean isGPSAvailable() { LocationManager alm = (LocationManager) APPContext.getContext() .getSystemService(Context.LOCATION_SERVICE); if (alm.isProviderEnabled(android.location.LocationManager.GPS_PROVIDER)) return true; return false; } public static void openGPS(Context context) { Intent intent = new Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS); context.startActivity(intent); } // ???????????? public static boolean isNetworkAvailable() { boolean result = true; final ConnectivityManager cm = (ConnectivityManager) APPContext .getContext().getSystemService(Context.CONNECTIVITY_SERVICE); final NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo == null || !networkInfo.isConnectedOrConnecting()) { result = false; } return result; } public static int getActiveNetworkType() { int defaultValue = -1; ConnectivityManager cm = (ConnectivityManager) APPContext.getContext() .getSystemService(Context.CONNECTIVITY_SERVICE); if (cm == null) return defaultValue; NetworkInfo info = cm.getActiveNetworkInfo(); if (info == null) return defaultValue; return info.getType(); } public static boolean isWifiActive() { ConnectivityManager connectivity = (ConnectivityManager) APPContext .getContext().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo[] info; if (connectivity != null) { info = connectivity.getAllNetworkInfo(); if (info != null) { for (int i = 0; i < info.length; i++) { if (info[i].getType() == ConnectivityManager.TYPE_WIFI && info[i].isConnected()) { return true; } } } } return false; } }