网络判断
来源:互联网 发布:思加图淘宝旗舰店真假 编辑:程序博客网 时间:2024/06/04 01:06
import android.app.AlertDialog;import android.content.ComponentName;import android.content.Context;import android.content.DialogInterface;import android.content.Intent;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.os.Build;import android.provider.Settings;public class NetStateUtil { public static boolean isConn(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); if (info != null && info.isAvailable()) { return true; } else { return false; } } public static void openDg(final Context context){ AlertDialog.Builder builder = new AlertDialog.Builder(context); builder.setMessage("是否要进行网路设置"); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { Intent intent=null; //判断手机系统的版本 即API大于10 就是3.0或以上版本 if (Build.VERSION.SDK_INT>10){ intent=new Intent(Settings.ACTION_WIRELESS_SETTINGS); }else { intent=new Intent(); ComponentName component = new ComponentName("com.android.settings","com.android.settings.WirelessSettings"); intent.setComponent(component); intent.setAction("android.intent.action.VIEW"); } context.startActivity(intent); } }); //AlertDialog.Builder builder1 = new AlertDialog.Builder(context); builder.setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); builder.create().show(); }} //判断网络连接 boolean result = NetStateUtil.isConn(this); if (result) { //进行网路请求 MYTask myTask = new MYTask();(开启异步线程:代码省略) myTask.execute(JSON_URL); } else { NetStateUtil.openDg(this); }
阅读全文
0 0
- 网络判断
- 网络判断
- 判断网络
- 判断网络
- 网络判断
- 判断网络
- 网络判断
- 网络判断
- 网络判断
- 判断网络
- 网络判断
- 判断网络
- 网络判断
- 判断网络
- 网络判断
- 判断网络
- 网络判断
- 网络判断
- ReadWriteLock场景应用
- 2222
- Java设计模式之单例模式(Singleton Pattern)
- gt-api-RC1.jar中Query类学习
- Angular4
- 网络判断
- 关于项目打成jar包文件资源找不到的同学们你们有救了!!!
- turtlebot使用 (一)
- 对Jquery中的ajax再封装,简化操作示例
- Error: could not call python function 'rosdep2.rospack.init_rospack_interface'
- 通过Spring @PostConstruct 和 @PreDestroy 方法 实现初始化和销毁bean之前进行的操作
- SSL P1072 砝码称重
- 集合中的List以及其三个实现类ArrayList,LinkedList,Vector
- 《spring cloud微服务实战》读书笔记——Spring Cloud Ribbon(一)RestTemplate