• 网络连接异常处理工具


    public class NetStateUtils {


    /**
    * 对网络连接状态进行判断
    *
    * @return true, 可用; false, 不可用
    */
    public static boolean isNetworkConnected(Context context) {
    if (context != null) {
    ConnectivityManager connManager = (ConnectivityManager) context
    .getSystemService(Context.CONNECTIVITY_SERVICE);
    NetworkInfo networkInfo = connManager.getActiveNetworkInfo();
    if (networkInfo != null) {
    return networkInfo.isAvailable();
    }
    }
    return false;
    }


    /**
    * 提示设置网络连接
    *
    */
    public static void alertSetNetwork(final Context context) {
    AlertDialog.Builder builder = new AlertDialog.Builder(context);
    builder.setTitle(context.getResources().getString(R.string.neterror)).setMessage(context.getString(R.string.question));

    builder.setPositiveButton(context.getResources().getString(R.string.set), new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    Intent intent = null;
    try {
    int sdkVersion = android.os.Build.VERSION.SDK_INT;
    if (sdkVersion > 10) {
    intent = new Intent(
    android.provider.Settings.ACTION_WIRELESS_SETTINGS);
    } else {
    intent = new Intent();
    ComponentName comp = new ComponentName(
    "com.android.settings",
    "com.android.settings.WirelessSettings");
    intent.setComponent(comp);
    intent.setAction("android.intent.action.VIEW");
    }
    context.startActivity(intent);
    } catch (Exception e) {
    e.printStackTrace();
    }
    }
    });
    builder.setNegativeButton(context.getString(R.string.cancle), new DialogInterface.OnClickListener() {
    @Override
    public void onClick(DialogInterface dialog, int which) {
    dialog.cancel();
    System.exit(0);
    System.gc();
    }
    });
    builder.show();
    }
    }
  • 相关阅读:
    浅拷贝与深拷贝
    省市县三级异步加载导航
    数据处理为树形结构以及多级菜单的逻辑分析
    九宫格
    数组及字符串方法
    定时器
    js,ajax获取数据
    js去重
    js常见排序
    SSH+DWZ、JQuery-UI ,swfobject.embedSWF属性与用法,IE下日期控件被flash控件挡住
  • 原文地址:https://www.cnblogs.com/zhou2016/p/5329495.html
Copyright © 2020-2023  润新知