示例#1
0
        public async Task UpdateLocation()
        {
            DB_Singleton db = DB_Singleton.Instance;

            if (db.IsOnline())
            {
                WifiManager wifimanager = (WifiManager)GetSystemService(Context.WifiService);

                string permission = Manifest.Permission.AccessFineLocation;
                if (CheckSelfPermission(permission) == (int)Permission.Granted)
                {
                    var InRange = wifimanager.ScanResults;

                    foreach (ScanResult network in InRange)
                    {
                        WifiNetworks.Add(network.Ssid);
                        //WifiNetworkKey.Add(network.Bssid);
                    }
                }

                RequestHandler request = new RequestHandler(this);

                var results = WifiNetworks.Intersect(db_locations);

                current_location = null;
                if (results.Count() != 0)
                {
                    current_location = results.ElementAt(0);
                }

                var response = await request.UpdateLocation(db.Retrieve("Token"), current_location);

                if (current_location != null)
                {
                    CurrentLocation.Text = "Current location: " + current_location;
                }
                else
                {
                    CurrentLocation.Text = "Not in range of location";
                }
                CurrentLocation.RefreshDrawableState();
            }
        }