检查网络是否连接的工具类
来源:互联网 发布:唱给自己的歌网络战队 编辑:程序博客网 时间:2024/05/18 16:57
必须先加下面这两个权限,网络访问权限和差来看网络状态权限<uses-permission android:name="android.permission.INTERNET"/><uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); listview = (ListView) findViewById(R.id.listview); if (isConnection(this)) { 下面这个方法是自定义的网络请求数据方法,就不上传了 getDataByWeb(); } else { AlertDialog.Builder builder = new AlertDialog.Builder(this); builder.setMessage("网络链接中断,是否设置链接网络"); builder.setNegativeButton("取消", null); builder.setPositiveButton("确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) {Intent intent = new Intent(); intent.setAction("android.net.wifi.PICK_WIFI_NETWORK"); startActivity(intent);} }); builder.create().show(); } } public boolean isConnection(Context context) { ConnectivityManager manager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo info = manager.getActiveNetworkInfo(); return (info != null && info.isAvailable()); }
阅读全文
0 0
- 检查网络是否连接的工具类
- 检查网络是否连接
- 检查网络是否连接
- 检查移动网络是否可用的工具
- C#检查网络是否连接的方法
- C#检查网络是否连接的方法
- 检查网络是否连接正常
- 检查是否连接到网络
- iOS检查网络是否连接
- 检查3G网络是否连接
- iOS检查网络是否连接
- Android检查网络是否连接
- 检查网络连接是否可用
- 检查网络是否连接正常
- Netstate检查网络是否连接
- 一个判断网络是否连接的工具类
- Android工具类整理(1)检查是否有网络、检查SD卡是否存在
- 判断网络是否连接工具类
- iOS 对象数组的深拷贝(NSCoding协议)
- Cows(凸包面积)
- native.js 安卓自动连接制定名称和密码的wifi
- hihocoder-1526 序列的值(DP/二进制)
- 学习JPA
- 检查网络是否连接的工具类
- 将unsigned char字符串以16进制的字符串显示
- 122. Best Time to Buy and Sell Stock II
- 【openjudge】单词接龙
- Java基础(一)变量与运算
- Javascript设计模式-05-外观模式
- C++中的TYPE、DWORD与WORD
- Spring学习(三):BeanFactory和ApplicationContext
- 在简历中使用STAR法则