protected override void OnDestroy() { if (mlock != null) { mlock.Release(); mlock = null; } base.OnDestroy(); }
protected override void OnDestroy() { //base.OnDestroy(); if (_mlock != null) { _mlock.Release(); _mlock = null; } base.OnDestroy(); }
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()); }
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()); }
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 }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Devices); // Create WiFi locks and mDNS scanner wifi = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService); mlock = wifi.CreateMulticastLock("Zeroconf Lock"); finder = new MDNSFinder(this); // Set events FindViewById <Button>(Resource.Id.btnScanNetwork).Click += (sender, args) => ScanNetwork(false); FindViewById <ListView>(Resource.Id.lvDevices).ItemClick += lvDevices_ItemClick; }
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); }
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); })); }
protected override void OnCreate(Bundle bundle) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; base.OnCreate(bundle); ZXing.Net.Mobile.Forms.Android.Platform.Init(); ZXing.Mobile.MobileBarcodeScanner.Initialize(Application); var wifi = (WifiManager)ApplicationContext.GetSystemService(Context.WifiService); mlock = wifi.CreateMulticastLock("Zeroconf lock"); HtmlLabelRenderer.Initialize(); global::Xamarin.Forms.Forms.Init(this, bundle); LoadApplication(new App()); }
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; }
public UdpHelper(WifiManager manager) { mylock = manager.CreateMulticastLock("UDPwifi"); }
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); })); }
protected override void onCreate(Bundle savedInstanceState) { base.onCreate(savedInstanceState); var sv = new ScrollView(this); var b2 = new Button(this); { var ll = new LinearLayout(this); //ll.setOrientation(LinearLayout.VERTICAL); sv.addView(ll); var b1 = new Button(this).AttachTo(ll); b1.WithText("LANBroadcastListener createMulticastLock"); var c = 0; b1.AtClick( v => { // server error { Message = , StackTrace = android.os.NetworkOnMainThreadException //at android.os.StrictMode$AndroidBlockGuardPolicy.onNetwork(StrictMode.java:1117) //at libcore.io.BlockGuardOs.sendto(BlockGuardOs.java:175) //at libcore.io.IoBridge.sendto(IoBridge.java:473) //at java.net.PlainDatagramSocketImpl.send(PlainDatagramSocketImpl.java:182) //at java.net.DatagramSocket.send(DatagramSocket.java:284) new Thread( delegate() { try { var socket = new DatagramSocket(); //construct a datagram socket and binds it to the available port and the localhos c++; var b = Encoding.UTF8.GetBytes(c + " hi from jvm!"); //creates a variable b of type byte var dgram = new DatagramPacket((sbyte[])(object)b, b.Length, InetAddress.getByName("239.1.2.3"), 40404); //sends the packet details, length of the packet,destination address and the port number as parameters to the DatagramPacket //dgram.setData(b); //System.Console.WriteLine( // "Sending " + b.Length + " bytes to " + dgram.getAddress() + ":" + dgram.getPort());//standard error output stream socket.send(dgram); //send the datagram packet from this port } catch (Exception ex) { System.Console.WriteLine("server error " + new { ex.Message, ex.StackTrace }); } } ) { Name = "sender" }.Start(); } ); b2.setText("The other button!"); ll.addView(b2); this.setContentView(sv); } // http://www.zzzxo.com/q/answers-android-device-not-receiving-multicast-package-13221736.html new Thread( delegate() { // http://stackoverflow.com/questions/12610415/multicast-receiver-malfunction // http://answers.unity3d.com/questions/250732/android-build-is-not-receiving-udp-broadcasts.html // Acquire multicast lock wifi = (WifiManager)getSystemService(Context.WIFI_SERVICE); multicastLock = wifi.createMulticastLock("multicastLock"); //multicastLock.setReferenceCounted(true); multicastLock.acquire(); System.Console.WriteLine("LANBroadcastListener ready..."); try { byte[] b = new byte[0x100]; // https://code.google.com/p/android/issues/detail?id=40003 var port = 40404; MulticastSocket socket = new MulticastSocket(port); // must bind receive side socket.setBroadcast(true); socket.setReuseAddress(true); socket.setTimeToLive(30); socket.setReceiveBufferSize(0x100); // https://code.google.com/p/android/issues/detail?id=40003 // http://stackoverflow.com/questions/6550618/multicast-support-on-android-in-hotspot-tethering-mode // http://www.massapi.com/class/java/net/InetSocketAddress.java.html // http://www.javadocexamples.com/java/net/MulticastSocket/joinGroup(SocketAddress%20mcastaddr,NetworkInterface%20netIf).html // http://grokbase.com/t/hadoop/common-issues/117jsjk8d7/jira-created-hadoop-7472-rpc-client-should-deal-with-the-ip-address-changes var group = InetAddress.getByName("239.1.2.3"); var groupSockAddr = new InetSocketAddress(group, port); // what lan interfaces do we have? socket.joinGroup(groupSockAddr, NetworkInterface.getByName("wlan0") ); System.Console.WriteLine("LANBroadcastListener joinGroup..."); while (true) { DatagramPacket dgram = new DatagramPacket((sbyte[])(object)b, b.Length); socket.receive(dgram); // blocks until a datagram is received var bytes = new MemoryStream((byte[])(object)dgram.getData(), 0, dgram.getLength()); var listen = Encoding.UTF8.GetString(bytes.ToArray()); System.Console.WriteLine("Received " + dgram.getLength() + " bytes from " + dgram.getAddress()); //dgram.setLength(b.Length); // must reset length field!s } } catch { System.Console.WriteLine("client error"); } } ) { Name = "client" }.Start(); }