|
@@ -15,32 +15,33 @@ import com.sheep.jiuyan.samllsheep.SheepApp;
|
|
|
public class NetUtil {
|
|
public class NetUtil {
|
|
|
private static NetUtil netUtil;
|
|
private static NetUtil netUtil;
|
|
|
|
|
|
|
|
- public static NetUtil getNetUtil(){
|
|
|
|
|
- if (netUtil == null){
|
|
|
|
|
|
|
+ public static NetUtil getNetUtil() {
|
|
|
|
|
+ if (netUtil == null) {
|
|
|
netUtil = new NetUtil();
|
|
netUtil = new NetUtil();
|
|
|
}
|
|
}
|
|
|
return netUtil;
|
|
return netUtil;
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ public static boolean CAN_CONNECT_SERVICE = true;//是否可以连接到服务器
|
|
|
|
|
+
|
|
|
/**
|
|
/**
|
|
|
* 判断网络是否连接
|
|
* 判断网络是否连接
|
|
|
*
|
|
*
|
|
|
* @param context
|
|
* @param context
|
|
|
* @return
|
|
* @return
|
|
|
*/
|
|
*/
|
|
|
- public static boolean isConnected(Context context)
|
|
|
|
|
- {
|
|
|
|
|
-
|
|
|
|
|
|
|
+ public static boolean isConnected(Context context) {
|
|
|
|
|
+ if(!CAN_CONNECT_SERVICE){
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
ConnectivityManager connectivity = (ConnectivityManager) SheepApp.getInstance()
|
|
ConnectivityManager connectivity = (ConnectivityManager) SheepApp.getInstance()
|
|
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
|
|
|
- if (null != connectivity)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (null != connectivity) {
|
|
|
|
|
|
|
|
NetworkInfo info = connectivity.getActiveNetworkInfo();
|
|
NetworkInfo info = connectivity.getActiveNetworkInfo();
|
|
|
- if (null != info && info.isConnected())
|
|
|
|
|
- {
|
|
|
|
|
- if (info.getState() == NetworkInfo.State.CONNECTED)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ if (null != info && info.isConnected()) {
|
|
|
|
|
+ if (info.getState() == NetworkInfo.State.CONNECTED) {
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -51,8 +52,7 @@ public class NetUtil {
|
|
|
/**
|
|
/**
|
|
|
* 判断是否是wifi连接
|
|
* 判断是否是wifi连接
|
|
|
*/
|
|
*/
|
|
|
- public static boolean isWifi(Context context)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public static boolean isWifi(Context context) {
|
|
|
ConnectivityManager cm = (ConnectivityManager) SheepApp.getInstance()
|
|
ConnectivityManager cm = (ConnectivityManager) SheepApp.getInstance()
|
|
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
|
|
@@ -65,8 +65,7 @@ public class NetUtil {
|
|
|
/**
|
|
/**
|
|
|
* 判断是否是流量连接
|
|
* 判断是否是流量连接
|
|
|
*/
|
|
*/
|
|
|
- public static boolean isMobile(Context context)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public static boolean isMobile(Context context) {
|
|
|
ConnectivityManager cm = (ConnectivityManager) SheepApp.getInstance()
|
|
ConnectivityManager cm = (ConnectivityManager) SheepApp.getInstance()
|
|
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
.getSystemService(Context.CONNECTIVITY_SERVICE);
|
|
|
|
|
|
|
@@ -79,8 +78,7 @@ public class NetUtil {
|
|
|
/**
|
|
/**
|
|
|
* 打开网络设置界面
|
|
* 打开网络设置界面
|
|
|
*/
|
|
*/
|
|
|
- public static void openSetting(Activity activity)
|
|
|
|
|
- {
|
|
|
|
|
|
|
+ public static void openSetting(Activity activity) {
|
|
|
Intent intent = new Intent("/");
|
|
Intent intent = new Intent("/");
|
|
|
ComponentName cm = new ComponentName("com.android.settings",
|
|
ComponentName cm = new ComponentName("com.android.settings",
|
|
|
"com.android.settings.WirelessSettings");
|
|
"com.android.settings.WirelessSettings");
|