I have Win32 desktop bridge application that uses background task to receive push notifications from WNS. I use UWP background task APIs over C++-WinRT
I'd like to be able to receive push notifications even when OS is in sleep so that it wakes up and the app handles push notification. By default OS does not wake up. It did only after manually changing settings value in System->Battery->See which apps are affecting your battery life->Click my app ->Uncheck Let Windows decide option (by default it is always checked) and check Allow the app to run background taks. Now I'd like to do this is manual work on code for better user experience.
RequestAccessKindAsync API allows to let user to change above setting value by showing popup notification to the user and I could do it without any problem in UWP C# sample app. But same code does not show pop notification from my desktop bridge over C++-WinRT. It simply returns false value for below code
auto result = co_await BackgroundExecutionManager::RequestAccessKindAsync(BackgroundAccessRequestKind::AlwaysAllowed,
L"App needs to use background to catch push notifications while device is in sleep");
Can anyone confirm that RequestAccessKindAsync API works from desktop bridge? If not then how I can make sure OS and the app will always be able to wake up from sleep when it receives push notification?
UPD: Raised request to enable this API from desktop brige here
This is a missing feature. When we designed this API a couple of releases ago we didn't consider desktop bridge apps would be calling it - but clearly there is a use case for supporting this. I have notified the team about this gap, but I'd also encourage you to log a feature request here: https://wpdev.uservoice.com/
Two possible workarounds:
(1) you could add a dummy/empty UWP foreground app to your desktop bridge app. You can then launch this on startup and request the background access from there. This will be a bit ugly, but you could make it look like a splash screen :-)
(2) you can instruct the user to go into the Settings app to set your app to always allowed. You can help them do that with a deep link to the battery save settings, but they will still need to manually flip the switch.
Related
I am new to .NET and seeking help for the Windows Service Updates Notifications.
I have a use case that is somewhat similar to "https://stackoverflow.com/questions/41232170/c-sharp-show-notification-prompting-a-update".
The application is developed in C#.NET and is deployed and running as Windows Service.
However, the application is not using any MSI installer to install it. I am using a batch script that configures the Windows Service application.
Now, I want to show the notifications about the updates about the Windows Service to the user, when the system gets restarted.
I came across about the usage of WCF or by using the Task Scheduler, but not sure which one would be the better solution.
Please advice.
Ok, there are (were, because MS disabled the first one that I'm going to explain) two ways to notify your user about updates from a service.
First, the bad, ugly (and non-working in recent versions) way: interactive services.
You can configure a service as interactive, if you add the SERVICE_INTERACTIVE_PROCESS flag the service will be able to create a GUI that will be attached to Display_0. This presents a ton of problems (trying to show a GUI when there's no user session, if you have two sessions open only the first one will show the GUI and so on) but it's a cheap dirty way to show data to the user. Avoid it.
Second, the right way: a standalone GUI program.
In this case you create a secondary program that will show the data to the user, you can start it with the user session or let the user decide if he wants to receive info by opening manually this application. This program needs to receive the updates from the service in some way, which is better is up to you but I would use UDP for this, in this way your service doesn't needs to care if any GUI app is connected or not, you broadcast an UDP message and everyone listening will receive it, you don't need to mantain a server that handles connections, you don't need to have an storage in order to maintain the event data and it will support any number of instances of the GUI (if more than one user has started a session in the machine all of them will get notified).
But as I said, that would be my preference, you can do it as fancy as you want, you can use Pipes, use a file that contains the event and use a FileSystemWatcher to get notified when changes happen in it, you can even host an ASP .net web app which implements a SignalR hub and then you can create your GUI in html. It's up to you decide which mechanism is the best for your scenario.
I've created a custom C#/WPF application that can send toast notifications that has an activator that can handle activation. I'm using WiX to deploy the solution and create a shortcut with ShortcutProperty elements for System.AppUserModel.ID and System.AppUserModel.ToastActivatorCLSID.
Everything works perfectly as expected but I wonder one thing. Is it possible to register the ToastActivator without creating a shortcut? This program is going to be used on an internal enterprise network and I don't intend for it to have any UI. It'll be launched by the Task Scheduler, check a web service and send toast messages to the user when they apply.
If I must have a shortcut, the best UX I can think of is to just diplay an about dialog and exit.
Based on the Application Model Microsoft has, any UWP feature like notification center, toasts etc can only be done by a registered application.
An application is "registered" when its added to the start menu with a link.
There has to be a valid shortcut with a System.AppUserModel.Id otherwise all the new win10 features do not work.
https://learn.microsoft.com/en-us/windows/win32/shell/quickstart-sending-desktop-toast
We're writing a cross-platform C# "Xamarin" application; right now we're just targeting the iPad. The application has two features relevant to this question:
The app requires that the user authenticate to the app (in addition to logging onto the iPad)
The app connects to a remote device over Bluetooth
So the question becomes, what happens when the user switches to another app, which results in our app's OnSleep() being called. In OnSleep() we could immediately disconnect Bluetooth and log out the user, but that seems like poor usability, especially if they are just quickly checking some alarm that triggered or an instant message that came in.
For the sake of usability, we're thinking to have a 1-minute timeout; if the user does in fact pop out and quickly pop back into the app, we'd like things to simply continue on without any loss of communication or re-authentication.
If, in OnSleep(), I set up a timer using Xamarin.Forms.Device.StartTimer(), that timer does not fire while the app is "asleep".
What does it take to have a small background task/thread/process execute, even while the app is asleep? Something that simply waits 1 minute, and then shuts down the Bluetooth communication and sets a flag indicating re-authentication is needed?
Can we run some task on specific time in background if my application is running or on dormant state. Is this possible in windows phone 7.5 Mango. If Its not possible then any work around with the help of push notifications.
If you are not the currently active application in Windows Phone your application is being tombstoned, which means that some of your state is saved and your application is halted (e.g. there is no code running for your application anymore).
Therefor you can not create code that allows your application to do anything at a specific time, without using push notification.
Even with push notification your options are very limited. It realy depends on what you want to happen when a notification arives.
I have an issue about Windows Mobile thread scheduling: I have an application (C#) that detects incoming calls on the telephone. It is said that the operating system is "fully multitasking and multithreaded".
Still, I can detect an incoming call, but after the call is detected, the system application, showing that there is a call incoming, takes over the focus.My application doesn't get to execute itself until the system window (with the call) is deactivated. (something happens with the call).
Is there anything I can set so that my thread (application) executes even when the system window is focused?
All solutions you can come up with for this are based on one thing: a hack. Windows Mobile is not meant to be customized as you wish - Windows CE is. You cannot override the default Windows Mobile phonecall UI, but you can put your own app above it with the correct API calls. However, it will flicker and it will look like s...t.