Create and maintain a SignalR connection in a WinRT Background Task - windows-runtime

I currently have a Windows Phone app that connects to a SignalR service to receive notification data. The service pushes data to the phone, which the app accepts, process etc and it’s all working as expected.
However, I would like the app to continue to receive the notification data when the app is suspended and no longer in the foreground, and display the notification data as a toast message.
From what I can see, the Background Task infrastructure offers no way to do this.
I have access to a Suspending and Resuming event (using Prism) so here I could Register/Unregister my background task.
For the trigger, the only one that comes close to being relevant is the TimeTrigger, but this only has a freshness time of 15 minutes, so assuming I am recreating the connection in the background task, I would end up opening and then instantly closing the connection every 15 minutes which isn't what I want to do.
I could have an “infinite await” that just hangs until a timeout, but this doesn't feel like the right way to go (and the resource usage would be terrible).
Is there a way around this to achieve what I want to do?

No, Windows Phone apps cannot keep a channel open like this. If the goal is only for toasts then you can do the computation on the server and push a toast notification.
Windows Store apps can do this with the ControlChannelTrigger class, but it is not supported on Windows Phone.

Related

Trigger BackgroundTask by calender events

Imagine a background task being registered to get triggered at a calender event (event from the build-in calender) from a Windows Phone 8.1 app. What are the possibilities for doing so?
As far as I prototyped it it is not possible to subscribe for the notifications. The only possibility I see is to copy all calender events at background task registration and let them sit in some owned cloud service that pushes raw notifications (raw notifications are very important) to my background task from WNS which requires internet connection which again is impractical. Moreover the service is required to be placed in lock screen. There are so many problems with synchronizing the calendar events if you think about it too.
The solution I would like to implement however should not require internet connection. How can I simplify it?
For more information on background tasks please visit https://blogs.msdn.microsoft.com/wsdevsol/2013/11/08/background-tasks-myths-and-realities/

Windows phone 8 push notifications

I have question about push notifications in Windows phone 8.
As i understand, there are three types of push notification:
Toast Notification.
Tile Notification.
Raw Notification.
So, in my opinion:
if the app is running, and opened in foreground:
Toast will be not shown, but i can handle it`s event and do something.
Tile will be updated automaticaly
Raw Notification must be handled by me. (Question one: can i do it without background task?)
if the app is running now, but suspended:
Toast will be shown as it came, without any event handling in my app, only "BindToToast()"
Tile Will be updated, without any event handling, only "BindToTile()"
Raw notification must be handled by background Task.
if the app is not open:
Toast will be shown automaticaly, if in previous launch "BindToToast()" was called.
Tile will update automaticaly, if in previous launch "BindToTile()" was called,
Question 2: what about raw notification? how to handle it here?
I think the situation is as follows:
Toast notification is shown only when the app is not running, but can be intercepted when it is
Tile notification always updates the tile regardless of application running
Raw notification can only be processed by the application when running.
Toast/raw notifications cannot normally be handled by a background task in Windows Phone 8.0. But there maybe a hack to get around this. See Windows Phone 8 notifications and background tasks and Windows Phone 8 Background Task with notifications
In Windows phone 8.1 it is quite possible to create a background task that is invoked when a notification is received, so the notification can be processed by the background task.

How to force an application to always run in background on Windows Phone 8.1 (or hide it from Battery Saver)?

I have recently been cleaning up my phone, reconfiguring apps etc and I found out there are a few third party apps that I can not - ever - disable from running in the background. They will always run.
Now, if I ever need to make one of my applications always run in the background, how would I do it on WP8.1? The third party applications seem somehow to be able to do it but I cannot find any reference to some permanent background process code which cannot be disabled?
I noticed the apps which run in the background cannot be disabled because they are listed as normal apps, not as apps which run in the background.
Here are some screenshots:
Kik Messenger and Messenger third party apps
Kik Messenger and Messenger in the Battery Saver dialog showing usage statistics, compare it to a non-background app named Games from Microsoft.
Here is the Battery Saver list of apps that *can run* in the background:
1
2
3
As is noticable - both of the apps are not there. What kind of magic coding has been used? Both apps seem to function in the background. 
I haven't confirmed this but my guess would be that those 2 apps are using VoipHttpIncomingCallTask agent and not using the other Voip tasks listed in http://msdn.microsoft.com/en-us/library/windows/apps/microsoft.phone.networking.voip(v=vs.105).aspx. If you have the time perhaps you can create a simple app in this manner to confirm this.
VoipHttpIncomingCallTask is invoked when the app receives a push notification for an "incoming call" (which would be sent by your app's cloud server for example). These apps are likely using this task to indicate a incoming chat has occurred (ex: by raising a toast for the incoming chat) instead of starting an incoming voip call (which would have invoked the incoming call UI).
Whether the Battery Saver app not showing these apps due to this reason is intentional or not is not clear to me. If it is indeed the reason I wouldn't assume this behavior would remain always as the Battery Saver app could be updated to treat these apps differently in the future.

Launch application automatically from a push notification on Windows Phone 8

I would like to launch an application using parameters provided from a push notification on Windows Phone 8.
The behaviour I wish to achieve is that as soon as the user receives the notification, the application will be launched with the parameters provided in the notification. I.e. seamlessly present the notification in a more user friendly way.
As far as I understood there are three push notification mechanisms. Toasts, Tiles and Raw.
None of them seems to be able to handle the wanted behaviour.
Toast: The message is shown even if the application hasn't been started. It does not start the application unless clicked on but seems to be closest to the target.
Tile: Message is shown if the application has been pinned. But they may be difficult to notice unless the tile is pinned fairly high on the start screen.
Raw: Works in more power states but requires the application to be running. This doesn't seem to be a match because I want the notification to be received when the application is not running. I couldn't find information about which application states where raw notifications are handled. I would prefer all.
Did I miss something in my research? If anyone has a hint of how to put an application in the foreground from a push notification (without user interaction) it would be greatly appreciated!
My first attempt was to trigger the application start using SMS but that seems to be a no go.
See my post Launch application automatically from an SMS on Windows Phone 8
You can not automatically launch an application on Windows Phone (and neither can you on iOS or Android). What you can do is provide a URI with the Push notification so the user is taken to a page with the needed information
you can not put an application in the foreground from background without user interaction.

Chrome apps that run on startup?

What would be the easiest way for me to set up a Chrome extension that starts when I log in to my Windows account, and can be connected to a WebSocket server to check for, say, new messages, and then pop open a desktop notification, that clicks to the messages web page?
I expect that making an extension is straight forward, as well as getting it to communicate with WebSockets, and making the desktop notification.
But what about making it automatically start when I log in to the computer? What would be a good way to do this in Windows? I am not interested in having the chrome browser to open up at log in, but I certainly don't mind if I see Chrome in the task bar.
You might look into chrome.runtime.onStartUp: https://developer.chrome.com/apps/runtime#event-onStartup, which is
"Fired when a profile that has this extension installed first starts up."
Also, you can use chrome.alarms to schedule a function to run every minute or so, to open a WebSocket somewhere, etc.
The app may try to unload itself if there are no active windows, so you can call some action in chrome.runtime.onSuspend (like loading an XHR somewhere) to cause onSuspendCanceled to trigger.