예제 #1
0
        static void StopListeners()
        {
            if (conectivityReceiver == null)
            {
                return;
            }

            try
            {
                UnregisterNetworkCallback();
            }
            catch
            {
                Debug.WriteLine("Connectivity receiver already unregistered. Disposing of it.");
            }

            try
            {
                Platform.AppContext.UnregisterReceiver(conectivityReceiver);
            }
            catch (Java.Lang.IllegalArgumentException)
            {
                Debug.WriteLine("Connectivity receiver already unregistered. Disposing of it.");
            }
            conectivityReceiver.Dispose();
            conectivityReceiver = null;
        }
예제 #2
0
        static void StartListeners()
        {
            Permissions.EnsureDeclared <Permissions.NetworkState>();

            conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);

#pragma warning disable CS0618 // Type or member is obsolete
            Platform.AppContext.RegisterReceiver(conectivityReceiver, new IntentFilter(ConnectivityManager.ConnectivityAction));
#pragma warning restore CS0618 // Type or member is obsolete
        }
예제 #3
0
        static void StartListeners()
        {
            Permissions.EnsureDeclared <Permissions.NetworkState>();

            var filter = new IntentFilter();

            if (Platform.HasApiLevelN)
            {
                RegisterNetworkCallback();
                filter.AddAction(Platform.EssentialsConnectivityChanged);
            }
            else
            {
#pragma warning disable CS0618 // Type or member is obsolete
                filter.AddAction(ConnectivityManager.ConnectivityAction);
#pragma warning restore CS0618 // Type or member is obsolete
            }

            conectivityReceiver = new ConnectivityBroadcastReceiver(OnConnectivityChanged);

            Platform.AppContext.RegisterReceiver(conectivityReceiver, filter);
        }