protected override void OnResume() { base.OnResume(); nsm = new NetworkStatusMonitor(); _nsbr = new NetworkStatusBroadcastReceiver(); _nsbr.ConnectionStatusChanged += _nsbr_ConnectionStatusChanged; RegisterReceiver(_nsbr, new IntentFilter(ConnectivityManager.ConnectivityAction)); //we have an image to place somewhere :D to the view provided earlier, if this isn't null if (!string.IsNullOrEmpty(imagePath)) { } }
public void Start () { if (_broadcastReceiver != null) { throw new InvalidOperationException ( "Network status monitoring already active."); } // Create the broadcast receiver and bind the event handler // so that the app gets updates of the network connectivity status _broadcastReceiver = new NetworkStatusBroadcastReceiver (); _broadcastReceiver.ConnectionStatusChanged += OnNetworkStatusChanged; // Register the broadcast receiver Application.Context.RegisterReceiver (_broadcastReceiver, new IntentFilter (ConnectivityManager.ConnectivityAction)); }
public void KillReceiver() { if (_nsbr == null) { throw new InvalidOperationException("Network status monitoring not active"); } try { UnregisterReceiver(_nsbr); _nsbr.ConnectionStatusChanged -= _nsbr_ConnectionStatusChanged; _nsbr = null; } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); NetworkStatusBroadcastReceiver _receiver = new NetworkStatusBroadcastReceiver(); Xamarin.Essentials.Platform.Init(this, bundle); global::Xamarin.Forms.Forms.Init(this, bundle); global::Xamarin.FormsMaps.Init(this, bundle); Plugin.CurrentActivity.CrossCurrentActivity.Current.Init(this, bundle); LoadApplication(new App(new PlugEVMePlatformModule())); IntentFilter _filter = new IntentFilter(); RegisterReceiver(_receiver, _filter); }
public void Stop() { if (_broadcastReceiver == null) { throw new InvalidOperationException ( "Network status monitoring not active."); } // Unregister the receiver so we no longer get updates. Application.Context.UnregisterReceiver (_broadcastReceiver); // Set the variable to nil, so that we know the receiver is no longer used. _broadcastReceiver.ConnectionStatusChanged -= OnNetworkStatusChanged; _broadcastReceiver = null; }