安卓--网络/GPS/WIFI/3G是否打开的简单封装
来源:互联网 发布:php会员登录代码 编辑:程序博客网 时间:2024/05/10 17:47
package com.sdp.panda.weatherquery.utils;import android.app.LoaderManager;import android.content.Context;import android.location.LocationManager;import android.net.ConnectivityManager;import android.net.NetworkInfo;import android.telephony.TelephonyManager;import android.widget.Toast;import java.util.List;/** * Created by 80926 on 2016/12/7. */public class NetUtils { private static ConnectivityManager cm; private static NetUtils instance; private Context mContext; private NetUtils(Context context) { cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); this.mContext = context; } /** * 判断网络是否打开 * * @param context * @return */ public static NetUtils getNetUtils(Context context) { if (instance == null) { synchronized (NetUtils.class) { if (instance == null) { instance = new NetUtils(context); } } } return instance; } public boolean isNetworkAvailable() { if (cm != null) { NetworkInfo[] infos = cm.getAllNetworkInfo(); if (infos != null) { for (int i = 0; i < infos.length; i++) { if (infos[i].getState() == NetworkInfo.State.CONNECTED) { return true; } } } } return false; } /** * 判读gps是否打开 * * @return */ public boolean isGpsEnabled() { LocationManager lm = (LocationManager) mContext.getSystemService(Context.LOCATION_SERVICE); List<String> providers = lm.getProviders(true); return providers != null && providers.size() > 0; } /** * 判读WIFI是否打开 */ public boolean isWifiEnabled() { TelephonyManager tm = (TelephonyManager) mContext.getSystemService(Context.TELEPHONY_SERVICE); return ((cm.getActiveNetworkInfo() != null && cm.getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || tm.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS); } /** * 判读3G是否打开 */ public boolean is3GNet() { NetworkInfo networkInfo = cm.getActiveNetworkInfo(); if (networkInfo != null && networkInfo.getType() == ConnectivityManager.TYPE_MOBILE) { return true; } return false; } /* 是否是wifi状态 */ public boolean isWifiStatue() { NetworkInfo activeNetworkInfo = cm.getActiveNetworkInfo(); if (activeNetworkInfo != null && activeNetworkInfo.getType() == ConnectivityManager.TYPE_WIFI) { return true; } return false; }}
0 0
- 安卓--网络/GPS/WIFI/3G是否打开的简单封装
- 判断网络类型:wifi , 3g, 4g 和GPS是否打开的方法
- 判断wifi或者3g是否打开的方法
- Android开发-常用工具方法(dp转成px、网络是否可用、是否3G网络、Gps是否打开、判断手机号码等)
- 判断网络是否,gps,wifi是否开启
- 安卓传感器+WIFI+GPS
- 3G网络的SUPLA-GPS定位技术
- Android中判断有无可用网络的代码(是否是3G或者WIFI网络)
- 能够检测iOS的WIFI,3G以及GPS的流量。
- 安卓 新版本 获取wifi状态网络是否可用等
- 判断是否连接网络,当前网络类型,Gps是否打开
- Android判断GPS、wifi、移动网络是否可用的探知函数
- 手机网络、WIFI、GPS定位策略(考验思维是否缜密的时候了)
- 安卓开发 检测WIFI是否打开,如果被关闭则自动打开。
- Android在代码中打开Wifi、移动网络和GPS
- Android在代码中打开Wifi、移动网络和GPS
- Android在代码中打开Wifi、移动网络和GPS
- Android在代码中打开Wifi、移动网络和GPS
- go中容易犯的错误
- 控件事件
- python 读取文本进行处理
- 1054. 求平均值 (20)
- 目标柏林
- 安卓--网络/GPS/WIFI/3G是否打开的简单封装
- 字符串之括号的有效性
- 通过实例来了解Activity生命周期
- 图像处理、图像识别、计算机视觉3者的异同
- QT常用问题
- excel笔记整理
- JAVA Web学习笔记4
- Android 关于使用阿里Freeline遇到的问题
- TextView 的一些常见属性