public class NetworkState {
    private static ConnectivityManager ctm;

    public NetworkState() {
    }

    public static boolean isOk(Activity act) {
        Context ctx = act.getApplicationContext();
        ctm = (ConnectivityManager) ctx
                .getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo infos = ctm.getActiveNetworkInfo();
        if (infos != null && infos.isAvailable()) {
            return true;
        }
        return false;
    }

    public static String getNetType(Activity act) {
        if (isOk(act)) {
            String netType = ctm.getActiveNetworkInfo().getTypeName()
                    .toLowerCase();
            return netType;
        }
        return null;
    }
}

相关文章:

  • 2022-02-03
  • 2022-12-23
  • 2021-07-16
  • 2022-03-04
  • 2022-12-23
  • 2021-11-14
  • 2022-12-23
猜你喜欢
  • 2022-01-07
  • 2021-12-23
  • 2022-02-17
  • 2021-07-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案