Android手机判断网络是否可用
来源:互联网 发布:东莞好玩的地方知乎 编辑:程序博客网 时间:2024/06/04 18:49
ConnectivityManager cm = (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); if (activeNetworkInfo == null) { Toast.makeText(this, "没有网络", Toast.LENGTH_SHORT).show(); } else { int type = activeNetworkInfo.getType(); if (type == cm.TYPE_WIFI) { if (activeNetworkInfo.isAvailable()){ Toast.makeText(this, "wifi可用", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(this, "wifi不可用", Toast.LENGTH_SHORT).show(); } } else if (type == cm.TYPE_MOBILE) { if (activeNetworkInfo.getExtraInfo().toLowerCase().equals("cmnet")) { if (activeNetworkInfo.isAvailable()){ Toast.makeText(this, "net网络可用", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(this, "net网络不可用", Toast.LENGTH_SHORT).show(); } } else { if (activeNetworkInfo.isAvailable()){ Toast.makeText(this, "wap网络网络可用", Toast.LENGTH_SHORT).show(); }else { Toast.makeText(this, "wap网络网络不可用", Toast.LENGTH_SHORT).show(); } } } }
0 0
- Android手机判断网络是否可用
- Android开发_判断手机网络是否可用
- android 判断网络是否可用
- Android判断网络是否可用
- Android 判断网络是否可用
- 【Android】判断网络是否可用
- Android 判断网络是否可用
- Android 判断网络是否可用
- Android 判断网络是否可用
- Android判断网络是否可用
- android判断网络是否可用
- android判断网络是否可用
- android判断网络是否可用
- android 网络判断是否可用
- android 判断网络是否可用
- Android判断网络是否可用
- android判断网络是否可用
- Android 判断网络是否可用
- JNI函数的注册方法
- c#中的代理模式
- 2. Add Two Numbers
- apple pay开发支付流程及绑卡流程
- E
- Android手机判断网络是否可用
- Makefile简介1
- 深度理解链式前向星
- nyoj93 汉诺塔(三)
- js面向对象之构造函数、封装与继承
- SpringJDBC 学习笔记
- 倍升工作效率的小策略
- Stealing Harry Potter's Precious
- 【英语小结】四月小结