Exemple #1
0
            public string AddNetworkSuggestion()
            {
                var suggestion = new WifiNetworkSuggestion.Builder()
                                 .SetSsid(Static.Secrets.PreferredWifi)
                                 .SetWpa2Passphrase(Static.Secrets.PrefferedWifiPassword)
                                 .Build();

                var suggestions = new[] { suggestion };
                var status      = wifi.AddNetworkSuggestions(suggestions);

                if (status != NetworkStatus.SuggestionsSuccess)
                {
                    status = wifi.RemoveNetworkSuggestions(suggestions);
                    status = wifi.AddNetworkSuggestions(suggestions);
                }

                var statusText = status switch
                {
                    NetworkStatus.SuggestionsSuccess => "Pomyślnie zasugerowano sieć",
                    NetworkStatus.SuggestionsErrorAddDuplicate => "Sugestia takiej sieci już istnieje",
                    NetworkStatus.SuggestionsErrorAddExceedsMaxPerApp => "Przekroczono limit ilości sugestii"
                };

                //var toast = Toast.MakeText(Application.Context, statusText, ToastLength.Long);
                //toast.Show();

                return(statusText);
            }
        private void SuggestNetwork()
        {
            var suggestion = new WifiNetworkSuggestion.Builder()
                             .SetSsid(_ssid.Text)
                             .SetWpa2Passphrase(_passphrase.Text)
                             .Build();

            var suggestions = new[] { suggestion };

            var wifiManager = GetSystemService(WifiService) as WifiManager;
            var status      = wifiManager.AddNetworkSuggestions(suggestions);

            var statusText = status switch
            {
                NetworkStatus.SuggestionsSuccess => "Suggestion Success",
                NetworkStatus.SuggestionsErrorAddDuplicate => "Suggestion Duplicate Added",
                NetworkStatus.SuggestionsErrorAddExceedsMaxPerApp => "Suggestion Exceeds Max Per App"
            };

            _statusText.Text = statusText;
        }