How does my app know if any incoming call coming to phone in Windows Phone 8? - windows-phone-8

My app is running on the foreground and the phone getting a incoming call. In the scenario, the phone is not raising any event to app like deactivated or closing. How do I identify my app not running ?

You app actually is still the current foreground app (so, kind of running, but audio/video is paused for obvious reasons).
You will get an Obscured event in the app, but you can't distinguish if this due to an incoming call, an incoming SMS, toast or reminder.
Here is a link to the MSDN documentation of the Obscured event you get. There is a corresponding Unobscured event you can also detect.

Related

Create and maintain a SignalR connection in a WinRT Background Task

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.

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.

Activated and deactivated events

When developing WP 8.1 Windows Runtime application, what’s the equivalent of the PhoneApplicationService.Activated and PhoneApplicationService.Deactivated events? It looks like PhoneApplicationService class is only available in Silverlight WP apps.
Application.Suspending event is not fired on Deactivated event (i.e. when I press Windows button).
You are right, under WinRT there is no Activated/Deactivated events. Your App can be Activated, but it's little different than in Silverlight. About the lifcycle you can read here at MSDN.
Your App will be Suspended just after you Navigate away from it. But - it's not working while you are debugging - more information here. When you run normally your App it will be suspended very fast after you hit Back/Start buttons.
About Navigation there is one thing you should be aware - when you Navigate away from the App, first OnNavigatedFrom is fired, then Suspended events (in the way you have subscribed them). But when you go back to your App - then Resuming events are fired, but OnNavigatedTo is not fired - reference:
Note On Windows Phone, OnNavigatedFrom() is called when the app is suspended. OnNavigatedTo() is not called when the app is resumed.
In some situations your App can be put into Not Running state. More again at Lifecycle at MSDN.

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.

How to detect calls while app is in the background?

So I understand that a foreground app can detect phone calls by registering for the obscured event, but while my app is running in the background, playing sound, sending notifications, etc, it does not hit the same event.
Is there a specific way to handle phone calls in this circumstance? The obscured event is the only one that I can find for detecting phone calls, but it won't work in this instance.
Unfortunately, with the current API there isn't...
In fact, I'd say that the obscured event can't even be considered a reliable way to detect an incoming phone call: you can use it right now for that purpose, but tomorrow Microsoft can just go ahead and add new stuff that will raise that very same event!