import android.content.Context; import android.net.ConnectivityManager; import android.net.NetworkInfo; public class SystemUtils { public static boolean checkNetworkStatus(Context context){ ConnectivityManager conMgr = (ConnectivityManager)context.getSystemService(context.CONNECTIVITY_SERVICE); if(conMgr.getActiveNetworkInfo() == null) return false; if(conMgr.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED ) return true; return false; } }
之後記得在Manifest.xml加入permission:
沒有留言:
張貼留言