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(安卓)Studio 使用中 遇到的那些奇奇怪怪的问题
  4. android个人错误,持续更新
  5. android判断是否连接网络
  6. android 自定义View 对话框
  7. Android(安卓)OkHttp 源码解析 - 拦截器
  8. android 捕捉app错误信息
  9. Android(安卓)studio 常见错误以及问题

随机推荐

  1. android studio 2.0Stable (正式版下载)
  2. Android中PopupWindow的用法(位置、动画
  3. Android(安卓)使用 adb命令 远程安装apk
  4. android 客户端无法解析php服务端返回的j
  5. android studio 运行程序提示"adb not re
  6. android摄像头采集和预览-第一种方法
  7. 【Android】解决sdcard not found 问题
  8. Android bluetooth介绍(二): android 蓝牙代
  9. Android背景--零碎小知识
  10. Android 调用UVCCamera 采集UVC摄像头数