예제 #1
0
        /// <summary>
        /// On create simply detect some of our managers
        /// </summary>
        public override void OnCreate()
        {
            base.OnCreate();
            //Find our audio and notificaton managers
            audioManager = (AudioManager)GetSystemService(AudioService);
            wifiManager  = (WifiManager)GetSystemService(WifiService);

            remoteComponentName = new ComponentName(PackageName, new RemoteControlBroadcastReceiver().ComponentName);
        }
예제 #2
0
 public Wifi()
 {
     Mvx.CallbackWhenRegistered <IMvxAndroidGlobals>(x =>
     {
         _manager =
             x.ApplicationContext.GetSystemService(Context.WifiService)
             .JavaCast <WifiManager>();
     });
 }
예제 #3
0
        public static void Register()
        {
            wifi = (WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService);

            // Start a scan and register the Broadcast receiver to get the list of Wifi Networks
            wifiReceiver = new WifiReceiver();
            Android.App.Application.Context.RegisterReceiver(wifiReceiver, new IntentFilter(WifiManager.ScanResultsAvailableAction));
            wifi.StartScan();
        }
예제 #4
0
        public async Task <string> GetWifiMacAddress()
        {
            string res = null;

            PermissionStatus status = await CrossPermissions.Current.CheckPermissionStatusAsync <LocationPermission>();

            if (status != PermissionStatus.Granted)
            {
                status = await CrossPermissions.Current.RequestPermissionAsync <LocationPermission>();
            }

            if (status == PermissionStatus.Granted)
            {
                WifiManager wifiManager = (WifiManager)(Application.Context.GetSystemService(Context.WifiService));
                res = wifiManager.ConnectionInfo.MacAddress;

                string macAddress = string.Empty;

                var all = Collections.List(Java.Net.NetworkInterface.NetworkInterfaces);

                foreach (var interfaces in all)
                {
                    if (!(interfaces as Java.Net.NetworkInterface).Name.Contains("wlan0"))
                    {
                        continue;
                    }

                    var macBytes = (interfaces as
                                    Java.Net.NetworkInterface).GetHardwareAddress();
                    if (macBytes == null)
                    {
                        continue;
                    }

                    var sb = new System.Text.StringBuilder();
                    foreach (var b in macBytes)
                    {
                        string convertedByte = string.Empty;
                        convertedByte = (b & 0xFF).ToString("X2") + ":";

                        if (convertedByte.Length == 1)
                        {
                            convertedByte.Insert(0, "0");
                        }
                        sb.Append(convertedByte);
                    }

                    macAddress = sb.ToString().Remove(sb.Length - 1);

                    return(macAddress);
                }
                return("02:00:00:00:00:00");
            }

            return(res);
        }
            public override void OnReceive(Context context, Intent intent)
            {
                // if wifi has been disabled then don't retrieve the results
                WifiManager wifi = (WifiManager)context.GetSystemService(Context.WifiService);

                if (!wifi.IsWifiEnabled)
                {
                    return;
                }

                var scanWiFiNetworks = wifi.ScanResults;

                foreach (ScanResult wifinetwork in scanWiFiNetworks)
                {
                    var network = new WiFiNetwork()
                    {
                        BSSID        = wifinetwork.Bssid,
                        SSID         = wifinetwork.Ssid,
                        Frequency    = wifinetwork.Frequency,
                        Capabilities = wifinetwork.Capabilities,
                        //TimeStamp = DateTimeOffset.FromFileTime(wifinetwork.Timestamp)
                        TimeStamp = DateTimeOffset.Now,
                        Location  = wiFiLocation,
                        Address   = wiFiAddress
                    };

                    // calculate the signal
                    int level          = WifiManager.CalculateSignalLevel(wifi.ConnectionInfo.Rssi, wifinetwork.Level);
                    int difference     = level * 100 / wifinetwork.Level;
                    int signalStrength = 0;

                    if (difference >= 100)
                    {
                        network.SignalStrength = 4;
                    }
                    else if (difference >= 75)
                    {
                        network.SignalStrength = 3;
                    }
                    else if (difference >= 50)
                    {
                        network.SignalStrength = 2;
                    }
                    else if (difference >= 25)
                    {
                        network.SignalStrength = 1;
                    }

                    if (!wiFiNetworks.Exists(n => n.SSID == network.SSID && n.BSSID == network.BSSID))
                    {
                        wiFiNetworks.Add(network);
                    }
                }

                thisActivity.UpdateList();
            }
예제 #6
0
        public NetworkService(NetworkConfigurationDroid configuration)
        {
            BaseUrl = configuration.BaseUrl;

            _Manager      = (ConnectivityManager)Application.Context.GetSystemService(Application.ConnectivityService);
            _WifiManager  = (WifiManager)Application.Context.GetSystemService(Application.WifiService);
            Configuration = configuration;

            Init();
        }
 private void AttachCallbacksAndIDs()
 {
     textMessage                = FindViewById <TextView>(Resource.Id.message);
     wifiManager                = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService);
     buttonCreateHotspot        = FindViewById <Button>(Resource.Id.hotspotBtn);
     buttonSendMessage          = FindViewById <Button>(Resource.Id.SendMessageButton);
     buttonCreateHotspot.Click += OnCreateNetworkButtonClick;
     buttonSendMessage.Click   += OnMessageSendButtonClick;
     LocalHotspot.StateChange  += OnHotspotStateChange;
 }
예제 #8
0
 public Wifi()
 {
     Mvx.IoCProvider.CallbackWhenRegistered <IMvxAndroidGlobals>(() =>
     {
         var globals = Mvx.IoCProvider.Resolve <IMvxAndroidGlobals>();
         _manager    =
             globals.ApplicationContext.GetSystemService(Context.WifiService)
             .JavaCast <WifiManager>();
     });
 }
예제 #9
0
        /// <summary>
        /// Включение Wi-Fi
        /// </summary>
        private void TurnOnWiFi()
        {
            WifiManager wifiManager = (WifiManager)Android.App.Application.Context.GetSystemService(Context.WifiService);

            if (!wifiManager.IsWifiEnabled)
            {
                // Active Wi-Fi connection.
                wifiManager.SetWifiEnabled(true);
            }
        }
예제 #10
0
        void getExternalSignUpUserSubscriptionxml(object sender, ExternalSignUpUserSubscriptionCompletedEventArgs e)
        {
            WifiManager wifiManager   = (WifiManager)GetSystemService(Context.WifiService);
            WifiInfo    wInfo         = wifiManager.ConnectionInfo;
            String      MACAdress     = Android.Provider.Settings.Secure.GetString(ContentResolver, Android.Provider.Settings.Secure.AndroidId);
            WebService  objWebService = new WebService();

            objWebService.GetEmpDetailsByEmpIDAsync(empid.ToString(), MACAdress);
            objWebService.GetEmpDetailsByEmpIDCompleted += getempxml;
        }
        public CustomNetworkCallback(WifiManager wifiManager, Action startLocationUpdates, Action stopLocationUpdates)
        {
            _wifiManager          = wifiManager;
            _startLocationUpdates = startLocationUpdates;
            _stopLocationUpdates  = stopLocationUpdates;

            _networkLogService = new NetworkLogService();
            _settingsService   = new SettingsService();
            IsConnected        = false;
        }
예제 #12
0
 public WifiReceiver(WifiManager wifiManager, Android.Widget.ListView wifiDeviceList, Context context, EditText pass, Button connectButton)
 {
     _wifiManager        = wifiManager;
     _wifiDeviceListView = wifiDeviceList;
     _context            = context;
     _password           = pass;
     _connectButton      = connectButton;
     AttachCallbacks();
     ShowButtonConnectState(true, true);
 }
        public TestAppWifiService()
        {
            WifiNetworks = new ObservableCollection <IWifiNetwork>();

            var wifiMonitor = new WifiMonitor();

            wifiMonitor.OnNetworkDetected += WifiMonitor_OnNetworkDetected;
            Application.Context.RegisterReceiver(wifiMonitor, new IntentFilter(WifiManager.ScanResultsAvailableAction));
            _wifiManager = ((WifiManager)Application.Context.GetSystemService(Context.WifiService));
        }
예제 #14
0
            public WifiReceiver(WifiManager wifi)
            {
                this.wifi    = wifi;
                wifiNetworks = new List <string>();
                wiFiInfos    = new List <WiFiInfo>();
                receiverARE  = new AutoResetEvent(false);

                //connectedSSID = ((WifiManager)wifi).ConnectionInfo.SSID.Replace("\"","");
                connectedSSID = ((WifiManager)wifi).ConnectionInfo.BSSID;
            }
예제 #15
0
        /**
         * 获取 MAC 地址
         * 须配置android.permission.ACCESS_WIFI_STATE权限
         */
        public static string getMacAddress(Context context)
        {
            //wifi mac地址
            WifiManager wifi = (WifiManager)context.GetSystemService(Context.WifiService);
            WifiInfo    info = wifi.ConnectionInfo;
            string      mac  = info.MacAddress;

            LogUtils.i(TAG, " MAC:" + mac);
            return(mac);
        }
예제 #16
0
 /**
  * 获取当前连接wifi的名称
  *
  * @return
  */
 public static String getConnectWifiSsid(Context context)
 {
     if (isWifiConnected(context))
     {
         WifiManager wifiManager = (WifiManager)context.GetSystemService(Context.WifiService);
         WifiInfo    wifiInfo    = wifiManager.ConnectionInfo;
         return(wifiInfo.SSID);
     }
     return(null);
 }
예제 #17
0
            public override void OnReceive(Context context, Intent intent)
            {
                var    mainActivity = (MainActivity)context;
                string action       = intent.Action;

                if (action == WifiManager.ScanResultsAvailableAction)
                {
                    WifiManager        wifiManager = (WifiManager)Android.App.Application.Context.GetSystemService(Android.Content.Context.WifiService);
                    IList <ScanResult> scanResults = wifiManager.ScanResults;
                }
            }
예제 #18
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            global::Xamarin.Forms.Forms.Init(this, bundle);

            wifi  = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService);
            mlock = wifi.CreateMulticastLock("Zeroconf lock");
            mlock.Acquire();
            SetPage(App.GetMainPage());
        }
예제 #19
0
        public string GetSSID()
        {
            string      wifi        = "Desconocida (Android)";
            WifiManager wifiManager = (WifiManager)(Application.Context.GetSystemService(Context.WifiService));

            if (wifiManager != null)
            {
                wifi = wifiManager.ConnectionInfo.SSID;
            }
            return(wifi);
        }
예제 #20
0
        private bool IsConnectedToWifi()
        {
            WifiManager wifiManager = (WifiManager)Activity.GetSystemService(Context.WifiService);

            if (wifiManager.IsWifiEnabled && wifiManager.ConnectionInfo?.NetworkId != -1)
            {
                return(true);
            }

            return(false);
        }
예제 #21
0
        public RadioStationServiceLock(Context context)
        {
            _wifiManager  = (WifiManager)context.GetSystemService(Context.WifiService);
            _powerManager = (PowerManager)context.GetSystemService(Context.PowerService);

            _wifiLock = _wifiManager.CreateWifiLock(WifiMode.Full, "wzxv.app");
            _wifiLock.Acquire();

            _powerWakeLock = _powerManager.NewWakeLock(WakeLockFlags.Partial, "wzxv.app");
            _powerWakeLock.Acquire();
        }
예제 #22
0
        public override void OnReceive(Context context, Intent intent)
        {
            IList <ScanResult> scanResults = new List <ScanResult>();
            WifiManager        manager     = (WifiManager)context.GetSystemService(Context.WifiService);

            foreach (var result in manager.ScanResults)
            {
                scanResults.Add(result);
            }
            this.onSuccess.Invoke(scanResults);
        }
예제 #23
0
        public void getDatosRedWifi()
        {
            //OBTENER DATOS WIFI O LOCAL
            WifiManager wifiManager = (WifiManager)Application.Context.GetSystemService(Service.WifiService);

            ip           = wifiManager.ConnectionInfo.IpAddress;
            SSID         = wifiManager.ConnectionInfo.SSID.Replace('"', ' ').Trim();
            conexionWifi = wifiManager.IsWifiEnabled;
            //  Toast.MakeText(this, "Conexión Wifi: " + conexionWifi + " IP: " + ip + " SSID: " + SSID, ToastLength.Short).Show();
            //FIN OBTENER WIFI O LACAL
        }
예제 #24
0
        public NetworkService(NetworkConfigurationDroid configuration)
        {
            BaseUrl = configuration.BaseUrl;

            _Manager       = (ConnectivityManager)Application.Context.GetSystemService(Application.ConnectivityService);
            _WifiManager   = (WifiManager)Application.Context.GetSystemService(Application.WifiService);
            _Configuration = configuration;

            //_Globals = Mvx.Resolve<IMvxAndroidGlobals>();

            Init();
        }
예제 #25
0
        private string GetAccessPointBSSID()
        {
            string accessPointBSSID = null;

            if (SensusServiceHelper.Get().WiFiConnected)
            {
                WifiManager wifiManager = Application.Context.GetSystemService(global::Android.Content.Context.WifiService) as WifiManager;
                accessPointBSSID = wifiManager.ConnectionInfo.BSSID;
            }

            return(accessPointBSSID);
        }
예제 #26
0
 public static string WifiBSSID()
 {
     try
     {
         WifiManager wifiManager = (WifiManager)Application.Context.GetSystemService(Context.WifiService);
         return(wifiManager.ConnectionInfo.BSSID);
     }
     catch (Exception ex)
     {
         return(null);
     }
 }
예제 #27
0
        private string GetAccessPointBSSID()
        {
            string accessPointBSSID = null;

            if (_connectivityManager.GetNetworkInfo(ConnectivityType.Wifi).IsConnected)
            {
                WifiManager wifiManager = Application.Context.GetSystemService(global::Android.Content.Context.WifiService) as WifiManager;
                accessPointBSSID = wifiManager.ConnectionInfo.BSSID;
            }

            return(accessPointBSSID);
        }
예제 #28
0
        private void _remove(string ssid, WifiManager wifi)
        {
            List <WifiConfiguration> existing = wifi.ConfiguredNetworks.Where(w => w.Ssid == "\"" + ssid + "\"").ToList <WifiConfiguration>();

            if (existing.Count() > 0)
            {
                foreach (WifiConfiguration config in existing)
                {
                    wifi.RemoveNetwork(config.NetworkId);
                }
            }
        }
예제 #29
0
 public AndroidWifiConnector()
 {
     try
     {
         _wifiManager = (WifiManager)Android.App.Application.Context
                        .GetSystemService(Context.WifiService);
     }
     catch (Exception ex)
     {
         OnError?.Invoke(new Exception("WifiConnector can not access the device WifiManager", ex));
     }
 }
예제 #30
0
 public static void InitWifiScan(Context ctx)
 {
     try
     {
         myWifiManager  = (WifiManager)ctx.GetSystemService(Context.WifiService);
         myWifiReceiver = new WifiReceiver();
     }
     catch (Exception ex)
     {
         AndroidLevelLogger.e(TAG, ex);
     }
 }