package com.util;import android.app.AlertDialog;import android.content.Context;import android.content.DialogInterface;import android.content.DialogInterface.OnClickListener;import android.content.Intent;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.net.NetworkInfo.State;import android.provider.Settings;public class InternetCheck {public static void checkInternet(final Context context){if(!isInternetAvilibal(context)){AlertDialog.Builder alert=new AlertDialog.Builder(context);alert.setMessage("抱歉网络连接错误,请重试").setPositiveButton("确定", new OnClickListener() {public void onClick(DialogInterface dialog, int which) {//使用provide打开连接context.startActivity(new Intent(Settings.ACTION_WIFI_SETTINGS));}}).setNegativeButton("取消", new OnClickListener() {public void onClick(DialogInterface dialog, int which) {dialog.dismiss();}});alert.show();}}public static boolean isInternetAvilibal(Context context){ConnectivityManager cmanager=(ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);if(cmanager==null){return false;}else{NetworkInfo[] infos=cmanager.getAllNetworkInfo();if(infos!=null){for(NetworkInfo info:infos){if(info.getState()==State.CONNECTED){return true;}}}}return false;}}

更多相关文章

  1. android个人错误,持续更新
  2. android判断是否连接网络
  3. Android 网络操作(上传下载等)
  4. 【android】监听网络变化连续多个广播的问题解决
  5. Android开发学习笔记整理(16)-网络请求
  6. android 捕捉app错误信息
  7. android 网络检测
  8. Android studio 常见错误以及问题
  9. android 判断网络是否连接

随机推荐

  1. 基于ARM Cortex-A8和Android(安卓)4.x的
  2. 【Android】进程间通信IPC——AIDL
  3. 酷炫的Android(安卓)QQ 开源了吧!!
  4. Android高手进阶教程(四)之----Android(
  5. Android屏幕计量单位详解
  6. Android(安卓)SDK 1.5中文版 (Applicatio
  7. Android牟利之道(二)--广告平台的介绍
  8. [置顶] 成功为Android系统配上了GNU开发
  9. Android高手进阶教程(二十三)之---Androi
  10. Android之替换APP字体——Typeface