-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetUtils
More file actions
73 lines (65 loc) · 2.19 KB
/
Copy pathNetUtils
File metadata and controls
73 lines (65 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import android.content.Context;
import android.location.LocationManager;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.telephony.TelephonyManager;
public class NetUtils {
/**
* @Title: isNetworkAvailable
* @Description: 判断是否连接网络
* @param context
* @return true为以连接网络,false为未连接网络 boolean
*/
public static boolean isNetworkAvailable(Context context) {
try {
NetworkInfo info = ZhimaApplication.getConnectivityManager().getActiveNetworkInfo();
if (info != null && info.isAvailable()) {
return true;
}
} catch (Exception e) {
return false;
}
return false;
}
/**
* @Title: isWifi
* @Description: 判断是否wifi网络
* @param context
* @return boolean
*/
public static boolean isWifi(Context context) {
NetworkInfo networkINfo = ZhimaApplication.getConnectivityManager().getActiveNetworkInfo();
if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_WIFI) {
return true;
}
return false;
}
/**
* @Title: isMobile
* @Description: 判断是否是移动网络
* @param context
* @return boolean
*/
public static boolean isMobile(Context context) {
NetworkInfo networkINfo = ZhimaApplication.getConnectivityManager().getActiveNetworkInfo();
if (networkINfo != null && networkINfo.getType() == ConnectivityManager.TYPE_MOBILE) {
return true;
}
return false;
}
/**
* @Title: isWifiEnabled
* @Description: 判断WIFI是否打开
* @param context
* @return boolean
*/
public static boolean isWifiEnabled(Context context) {
TelephonyManager mgrTel = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
return ((ZhimaApplication.getConnectivityManager().getActiveNetworkInfo() != null && ZhimaApplication.getConnectivityManager().getActiveNetworkInfo().getState() == NetworkInfo.State.CONNECTED) || mgrTel
.getNetworkType() == TelephonyManager.NETWORK_TYPE_UMTS);
}
public static boolean isGpsEnabled(Context context){
LocationManager mLocationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return mLocationManager.isProviderEnabled(LocationManager.GPS_PROVIDER);
}
}