1
wxr
2023-03-31 7e42cc13a14b7de31c9f5d5c61cdf24f3246335d
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
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;
            }
 
        }
    }
}