Example #1
0
        public override bool OnStartJob(JobParameters parm)
        {
            Log.Debug(TAG, "OnStartJob");

            jobParam = parm;
            settings = JsonConvert.DeserializeObject <SettingsModel>(jobParam.Extras.GetString("settings"));

            ConnectivityManager connManager = (ConnectivityManager)GetSystemService(ConnectivityService);

            if (connManager != null)
            {
                var builder = new NetworkRequest.Builder();
                builder.AddTransportType(TransportType.Wifi);
                builder.AddTransportType(TransportType.WifiAware);
                builder.AddTransportType(TransportType.Cellular);

                connectivityCallback = new ConnectivitiyCallback(this);
                connManager.RegisterNetworkCallback(builder.Build(), connectivityCallback);
            }
            else
            {
                return(false);
            }

            return(true);
        }
        public void StartMonitoring()
        {
            if ((_applicationContext == null) ||
                (_networkBroadcastReceiver == null))
            {
                return;
            }

            var networkRequest = new NetworkRequest.Builder()
                                 .AddTransportType(TransportType.Cellular)
                                 .AddTransportType(TransportType.Wifi)
                                 .AddTransportType(TransportType.WifiAware)
                                 .Build();

            var networkCallback = new CMPNetworkCallback(_applicationContext,
                                                         _connectivityManager);

            _connectivityManager.RegisterNetworkCallback(networkRequest,
                                                         networkCallback);

            var intentFilter = new IntentFilter(CMPNetworkBroadCastReceiver
                                                .KNetworkStatusChanged);

            _applicationContext.RegisterReceiver(_networkBroadcastReceiver,
                                                 intentFilter);
        }
Example #3
0
        /// <summary>
        /// Forces the cellular over wifi.
        /// </summary>
        public void ForceCellularOverWifi()
        {
            ConnectivityManager connection_manager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);

            NetworkRequest.Builder request = new NetworkRequest.Builder();
            request.AddTransportType(TransportType.Cellular);

            connection_manager.RegisterNetworkCallback(request.Build(), new CustomNetworkAvailableCallBack());
        }
Example #4
0
        public NetworkStatus(Context context, Action connected = null, Action disconnected = null)
        {
            _manager = (ConnectivityManager)context.GetSystemService(Context.ConnectivityService);

            if (connected != null)
            {
                Connected += (_, __) => connected();
            }
            if (disconnected != null)
            {
                Disconnected += (_, __) => disconnected();
            }

            var request = new NetworkRequest.Builder()
                          .AddTransportType(TransportType.Cellular)
                          .AddTransportType(TransportType.Wifi)
                          .Build();

            _manager.RegisterNetworkCallback(request, this);
        }