Xamarin Android 10 UDP Client In Background (Release Mode Only) - xamarin

I am having an issue with the UDPClient in Android 10 (worked fine in Android 9) so Im assuming Im missing from Android 10 that I have yet to be able to find so far.
I have a UDPService (background service) running which is a pretty standard implementation (Port is 64200)
m_udpSocket = new UdpClient(m_port);
m_udpSocket.Client.ReceiveTimeout = (int)m_healthTimeout.TotalMilliseconds;
m_healthSocket.Client.SetSocketOption( SocketOptionLevel.Socket, SocketOptionName.ReceiveTimeout, (int)m_healthTimeout.TotalMilliseconds );
I wont post the sending and receiving code at this stage as I think its more permissions related.
The client periodically sends some UDP data to the server for processing. Its all local network based (not internet) and the data is sent via the WiFi on the device.
In Android 9, it all works as expected with the app in the foreground or the background.
In Android 10, it works perfectly when the app is in the foreground, but when the app goes to the background, when I try to issue the send on the socket
System.Net.Sockets.SocketException (0x80004005): Access denied
This error only happens in release mode on Android 10. If Im running in Debug Mode attached to the device, I can put the app into the background and the UDP traffic works as expected.
Based on all the above, Im assuming there is something else I need to do to allow the socket to work in the background in release mode but I cant seem to put my finger on what it is. Ive read about INTERNET permission and how Debug mode automatically adds this so is there something else I may be missing in the Android Manifest that could cause this.
Any help would be greatly appreciated.
Thanks in advance.

For anyone experiencing similar problems, in the end it had nothing to do with the actual code, but it was the Battery Optimisation Settings in Android.
Once I removed the app from the automatic battery optimisations, everything worked as expected.

Related

Turn On macOS Screen Remotely

Is there a way to turn on the monitor remotely on macOS? I'm trying to write an app that will do this.
I've tried a couple of things but can't seem to find a way of triggering the screen to turn on after it has been turned off for power saving.
I've got a macOS app that advertises itself on the network via Bonjour. I can communicate to it via sockets, even when the computer is sleeping. However, I'm not sure what I can do from this macOS app that would trigger the screen to come on. I've tried sending a WoL packet and I've tried using Caffiene.
The macOS app doesn't need to pass Apple Review so I'm fine with using private APIs if necessary.

how to open a local web project in ios simulator in Visual Studio?

Let say I have an angular project on local, separating back-end and front-end. After starting my BE, I am able to consume my front-end accessing http://localhost:4200/ in browser.
If both my BE and FE have been started, is there a way to access http://localhost:4200/ or http://[myipaddress]:4200/ in an iOS simulator safari, so that I can see my staging result in the simulator?
I know Chrome and any other browser is able to simulate mobile devices in device mode, unfortunately, there are results in a real device that are different than that in device mode. Thus I really want to find a way to see the bug fixing result in an iOS simulator without deploying to production.
I tried to set inbound rule for port 4200 and accessed http://[myipaddress]:4200 in safari in a simulator , it said 'Safari could not open the page because the server stopped responding'. (myipaddress = IPv4 Address in ipconfig).
Any hints?
You may have something in your specific setup stopping you from doing so, but you could just use the simulator included with Xcode, which should have no issues connecting to your localhost address on a given port.

Chromecast sender app from Chrome on Android failing

I'm building a Cast app with a chrome sender and custom HTML/CSS/JS receiver. While it works correctly from desktop chrome, I've noticed that I can't connect via the Android Chrome app.
With Android, when clicking the Cast button and selecting the correct receiver device in the Popup, nothing happens (my listener for SESSION_STATE_CHANGE is not called). After clicking the button again, my session listener says:
{type: "sessionstatechanged",
session: null,
sessionState: "SESSION_START_FAILED",
errorCode: "invalid_parameter"}
At first, I thought my setup was incorrect, but after looking at the official chrome sender app and following the same steps as above, I noticed a similar problem with a different error code:
Request session failure:
{"code":"invalid_parameter",
"description":"Already requesting session",
"details":null}
In the above case the visual indicator starts it's 'active' state on first click, but there's no change/activity otherwise it just stays in that state.
This was working before, so I know this is a relatively new issue (at least since Feb, possibly sooner). I also know since it's working on desktop, there's nothing wrong with the setup per se -- but it's still failing for Android.
Any help or feedback here would be great, thank you!
Okay, after updating my Android phone (missed an update this morning) it seems to be fixed.
EDIT:
Turns out, it was due to the restart. So as a patch, restarting your mobile device will reset your Chrome and allow it to send correctly.

Pebble.js WatchApp displays: "Disconnected - run the pebble phone app"

I can't find much documentation around this issue. All other running apps on my pebble have a connection to my phone, and work as expected. However, a Pebble.js application I'm currently working on simply displays Disconnected - run the pebble phone app.
I have noticed that in my Developer Settings that the Connection Manager is listed as Disconnected. Is this part of the problem? I see nothing in the logs.
For reference, the application is doing a simple ajax request and displaying the result.
This message is often caused by the JavaScript crashing on the phone (undefined reference, unknown function, etc) and so the watch thinks it is not running.
Some ideas to debug this:
Replace your code with one very simple console.log("hello world") statement and see if this works.
Look at the Logs (View Logs button in CloudPebble or pebble logs on the command line).
Very rarely, on Android, I have seen situation where the Pebble app is in a bad state where it cannot execute the JS for only one app. When this happens, you need to force-kill the Pebble app and relaunch it.
I have had the same experience.
I usually kill and restart the pebble app on my phone and then I also do refresh the browser. Sometimes you have to log out of and then log back into Cloudpebble.

Sphero Windows Sample App?

Has anyone gotten the Sample BasicDriveApp App working in Windows 8?
https://github.com/orbotix/Sphero-Win-SDK
When I build and run the Project I get a message "No Sphero is connected" and when I try to connect the Sphero via Windows 8 Bluetooth it does not work.
Can anyone offer any tips?
Thanks.
John.
It indeed works, I've had some problems with connectivity myself, however.. process I use to restore if all goes awry:
Refresh Sphero (return to base for sleep mode, wait a few seconds, wake up)
Refresh Bluetooth in Windows (off / on) without connecting to Sphero
Open your app, wait for it to connect. It'll find Sphero and automatically dig in if all goes well.
[Update]
It appears Windows 8.1 doesn't really know what to do with Sphero. It has a hard time reconnecting after the connection is lost, even if you close all instances of the app and toggle through Bluetooth.

Resources