コード例 #1
0
ファイル: DevicesActivity.cs プロジェクト: Duet3D/FindMyDuet
        private async Task ScanNetwork(bool firstStart)
        {
            RunOnUiThread(() =>
            {
                SetScanState(true);
                FindViewById <ListView>(Resource.Id.lvDevices).Adapter = null;
            });

            try
            {
                mlock.Acquire();
                await finder.DiscoverBoards();
            }
            finally
            {
                mlock.Release();
            }

            RunOnUiThread(() =>
            {
                SetScanState(false);

                FindViewById <ListView>(Resource.Id.lvDevices).Adapter = new ArrayAdapter(this, Android.Resource.Layout.SimpleListItem1, finder.Boards.ToList());
                if (firstStart && finder.Boards.Count == 1)
                {
                    // If the app is starting and there is only one device available, connect to it immediately
                    GoToIP(finder.Boards[0].IPAddress);
                }
            });
        }
コード例 #2
0
ファイル: MainActivity.cs プロジェクト: softlion/Zeroconf
        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());
        }
コード例 #3
0
 protected override void OnCreate(Bundle bundle)
 {
     _wifi  = (WifiManager)ApplicationContext.GetSystemService(WifiService);
     _mlock = _wifi.CreateMulticastLock("Zeroconf lock");
     _mlock.Acquire();
     TabLayoutResource = Resource.Layout.Tabbar;
     ToolbarResource   = Resource.Layout.Toolbar;
     base.SetTheme(Resource.Style.MainTheme);
     base.OnCreate(bundle);
     CrossFingerprint.SetCurrentActivityResolver(() => this);
     Forms.Init(this, bundle);
     LoadApplication(new App());
 }
コード例 #4
0
ファイル: MainActivity.cs プロジェクト: zezba9000/Zeroconf
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

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

            wifi  = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService);
            mlock = wifi.CreateMulticastLock("Zeroconf lock");
            mlock.Acquire();
#pragma warning disable CS0618 // Type or member is obsolete
            SetPage(App.GetMainPage());
#pragma warning restore CS0618 // Type or member is obsolete
        }
コード例 #5
0
        private ProtoPadServer(Activity activity, int?overrideListeningPort = null, string overrideBroadcastedAppName = null)
        {
            _contextActivity = activity;

            BroadcastedAppName = overrideBroadcastedAppName ?? String.Format("ProtoPad Service on ANDROID Device {0}", Android.OS.Build.Model);
            ListeningPort      = overrideListeningPort ?? 8080;
            LocalIPAddress     = Helpers.GetCurrentIPAddress();

            var mainMonodroidAssembly = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name.ToLower() == "mono.android");

            var requestHandlers = new Dictionary <string, Func <byte[], string> >
            {
                { "GetMainXamarinAssembly", data => mainMonodroidAssembly.FullName },
                { "WhoAreYou", data => "Android" },
                { "ExecuteAssembly", data =>
                  {
                      var response = "{}";
                      var remoteCommandDoneEvent = new AutoResetEvent(false);
                      _contextActivity.RunOnUiThread(() => Response(data, remoteCommandDoneEvent, ref response));
                      remoteCommandDoneEvent.WaitOne();
                      return(response);
                  } }
            };

            _httpServer = new SimpleHttpServer(ListeningPort, requestHandlers);

            IPAddress broadCastAddress;

            using (var wifi = _contextActivity.GetSystemService(Android.Content.Context.WifiService) as WifiManager)
            {
                try
                {
                    _mcLock = wifi.CreateMulticastLock("ProtoPadLock");
                    _mcLock.Acquire();
                }
                catch (Java.Lang.SecurityException e)
                {
                    Debug.WriteLine("Could not optain Multicast lock: {0}. Did you enable CHANGE_WIFI_MULTICAST_STATE permission in your app manifest?", e.Message);
                }

                broadCastAddress = GetBroadcastAddress(wifi);
            }

            var inEmulator = Build.Brand.Equals("generic", StringComparison.InvariantCultureIgnoreCase);

            _udpServer = new UdpDiscoveryServer(BroadcastedAppName, String.Format("http://{0}:{1}/", inEmulator ? "localhost" : LocalIPAddress.ToString(), inEmulator ? "?" : ListeningPort.ToString()), broadCastAddress);
        }
コード例 #6
0
ファイル: MainActivity.cs プロジェクト: SzwedzikPL/TacControl
        protected override void OnCreate(Bundle savedInstanceState)
        {
            AppCenter.Start("b17f9c9d-e90c-488f-8c4b-92ef3e305c0d", typeof(Analytics), typeof(Distribute));


            WifiManager wifiMgr = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService);

            castLock = wifiMgr.CreateMulticastLock("TacControl-udp");
            castLock.SetReferenceCounted(true);
            castLock.Acquire();


            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            Android.Views.Window window = Window;
            window.AddFlags(WindowManagerFlags.KeepScreenOn);
            window.AddFlags(WindowManagerFlags.Fullscreen);

            LoadApplication(new App((action) =>
            {
                TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
                bool isMain = MainThread.IsMainThread;

                RunOnUiThread(() =>
                {
                    try
                    {
                        action();
                        tcs.SetResult(null);
                    }
                    catch (Exception ex)
                    {
                        tcs.SetException(ex);
                    }
                });

                return(tcs.Task);
            }));
        }
コード例 #7
0
        public GLOSAWiFiService()
        {
            ServiceEnabled   = false;
            ServiceAvailable = true;
            Connected        = false;

            _wifiManager = (WifiManager)Application.Context.GetSystemService(Android.Content.Context.WifiService);

            if (_wifiManager != null)
            {
                // Make sure system doesn't save power by disabling WiFi
                _wifiManager.CreateWifiLock(Android.Net.WifiMode.Full, "myLockId");

                // this is a work around for Android devices that are by default prevented from receiving broadcast messages
                WifiManager.MulticastLock loc = _wifiManager.CreateMulticastLock("Log_Tag");
                loc.Acquire();
            }

            _tryingToConnect = false;
        }
コード例 #8
0
ファイル: MainActivity.cs プロジェクト: stratosamu/TacControl
        protected override void OnCreate(Bundle savedInstanceState)
        {
            AppCenter.Start("b17f9c9d-e90c-488f-8c4b-92ef3e305c0d", typeof(Analytics), typeof(Distribute));

            var versionInfo = Application.Context.ApplicationContext?.PackageManager?.GetPackageInfo(Application.Context.ApplicationContext.PackageName, 0);

            //var username = System.Security.Principal.WindowsIdentity.GetCurrent();

            SentryXamarin.Init(o =>
            {
                o.AddXamarinFormsIntegration();
                o.Dsn         = "https://[email protected]/5390642";
                o.Release     = $"TacControl@{versionInfo?.VersionName}:{versionInfo?.LongVersionCode}";
                o.Environment = //username == "Dedmen-PC\\dedmen" ? "Dev" :
                                "Alpha";
            });


            WifiManager wifiMgr = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService);

            wifiLock = wifiMgr.CreateWifiLock(WifiMode.Full, "TacControl-udp");
            wifiLock.SetReferenceCounted(true);
            wifiLock.Acquire();
            castLock = wifiMgr.CreateMulticastLock("TacControl-udp");
            castLock.SetReferenceCounted(true);
            castLock.Acquire();


            ConnectivityManager conMgr = (ConnectivityManager)ApplicationContext.GetSystemService(Context.ConnectivityService);
            var stuff   = conMgr.GetAllNetworks();
            var wifiNet = stuff.FirstOrDefault(x => conMgr.GetNetworkInfo(x).Type == ConnectivityType.Wifi);

            if (wifiNet != null)
            {
                var res  = conMgr.BindProcessToNetwork(wifiNet);
                var info = conMgr.GetNetworkInfo(wifiNet);

                var connInfo = wifiMgr.ConnectionInfo;
            }


            //Networking.ConnectionInfo

            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource   = Resource.Layout.Toolbar;

            base.OnCreate(savedInstanceState);

            Xamarin.Essentials.Platform.Init(this, savedInstanceState);
            global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

            Android.Views.Window window = Window;
            window.AddFlags(WindowManagerFlags.KeepScreenOn);
            window.AddFlags(WindowManagerFlags.Fullscreen);

            LoadApplication(new App((action) =>
            {
                TaskCompletionSource <object> tcs = new TaskCompletionSource <object>();
                bool isMain = MainThread.IsMainThread;

                RunOnUiThread(() =>
                {
                    try
                    {
                        action();
                        tcs.SetResult(null);
                    }
                    catch (Exception ex)
                    {
                        tcs.SetException(ex);
                    }
                });

                return(tcs.Task);
            }));
        }