判断网络是否可用
来源:互联网 发布:超人电力软件 编辑:程序博客网 时间:2024/05/21 11:09
package com.example.netconnected.util;import android.content.Context;import android.content.DialogInterface;import android.content.Intent;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.support.v7.app.AlertDialog;/*** 判断网络是否可用* */public class IsNetConnect { public static boolean isNetWorkConnected(Context context) { if (context != null) { // 获取手机所有连接管理对象(包括对wi-fi,net等连接的管理) ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); // 获取NetworkInfo对象 NetworkInfo networkInfo = manager.getActiveNetworkInfo(); //判断NetworkInfo对象是否为空 if (networkInfo != null) return networkInfo.isAvailable(); } return false; } /** * 网络状态不可用的时候弹出dialog,,,是否跳转设置 */ public static void showNoNetWorkDlg(final Context context) { AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage("当前网络不可用,是否设置") .setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 跳转到系统的网络设置界面 Intent intent = null; // 先判断当前系统版本 if (android.os.Build.VERSION.SDK_INT > 10) { // 3.0以上 intent = new Intent(android.provider.Settings.ACTION_WIRELESS_SETTINGS); } else { intent = new Intent(); intent.setClassName("com.android.settings", "com.android.settings.WirelessSettings"); } context.startActivity(intent); } }).setNegativeButton("取消", null).show(); }}
阅读全文
1 0
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断网络是否可用
- 判断是否有可用网络
- 判断数据网络是否可用
- android 判断网络是否可用
- 判断当前网络是否可用
- Android判断网络是否可用
- Android 判断网络是否可用
- myeclipse 2014 去掉 默认加载的derby
- org.apache.ibatis.binding.BindingException
- 2017亚洲区域赛青岛赛区网络赛---1011题目(详细解答,AC)A Cubic number and A Cubic Number
- 写入SD卡
- Imageloader的使用
- 判断网络是否可用
- 粗谈Servlet运行原理
- 111
- windows7性能优化
- CodeforceF. Wizard's Tour
- C++复习第一天 静态类成员实现单例模式
- 20170918心情总结
- 字节数组转16进制输出
- 每日一点C语言--蛇形填数