using System;
|
using System.Linq;
|
using Xamarin.Essentials;
|
|
namespace com.hdl.on
|
{
|
public class NetworkUtils
|
{
|
public NetworkUtils ()
|
{
|
}
|
|
|
public static int CheckConnectedMode ()
|
{
|
try {
|
var profiles = Connectivity.ConnectionProfiles;
|
var access = Connectivity.NetworkAccess;
|
if (access != NetworkAccess.Internet) {
|
//网络不可访问
|
return 0;
|
}
|
if (profiles.Contains (ConnectionProfile.WiFi)) {
|
//
|
return 2;
|
} else if (profiles.Contains (ConnectionProfile.Cellular)) {
|
//手机蜂窝网络
|
return 1;
|
} else {
|
return 2;
|
}
|
} catch {
|
return 2;
|
}
|
|
}
|
}
|
}
|