Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Phone 8 notifications and background tasks

I have searched the official forums and documentation and all other places, but haven't been able to find a concrete answer.

Q. In Windows Phone 8, is it possible for an application to respond to a Push Notification, and perform a task, while it is in the background?

As far as I can understand, for Toast and Tile Notifications, when the app is not in the foreground, there are no hooks at all for it to be able to respond to the incoming message.

I think "raw notifications" are the correct choice for this, since I am not required to update the app tile, or even show a Toast Notification. But, I haven't been able to find an example, or in the documentations, if I can do this.

I have found several links which talk about doing this for Windows store apps, but I want to find out if this can be done for Windows Phone 8.

I have checked this other thread,

Windows Phone 8 Background Task with notifications

Where one of the answer suggests that Whatsapp actually has a hack for this, to download the messages after a push notification is received. So, is the answer to my question, a NO?

like image 959
Kumar Bibek Avatar asked Jan 13 '14 06:01

Kumar Bibek


2 Answers

Answer to your question is not exactly "NO", and you are right whatsapp uses hack for this, whatsapp someyow use AudioAgent, as they are allowed to run in background,

i dont know how exactly they do it, i am also searching for the same answer, let's see if i find something will post here

like image 179
maxchirag Avatar answered Oct 22 '22 17:10

maxchirag


This has changed in Windows Phone 8.1. From Raw notification overview (Windows Runtime apps)

Receiving a raw notification

There are two avenues through which your app can be receive raw notifications:

  • Through notification delivery events while your application is running.
  • Through background tasks triggered by the raw notification if your app is enabled to run background tasks.

An app can use both mechanisms to receive raw notifications. If an app implements both the notification delivery event handler and background tasks that are triggered by raw notifications, the notification delivery event will take priority when the app is running.

  • If the app is running, the notification delivery event will take priority over the background task and the app will have the first opportunity to process the notification.
  • The notification delivery event handler can specify, by setting the event's PushNotificationReceivedEventArgs.Cancel property to true, that the raw notification should not be passed to its background task once the handler exits. If the Cancel property is set to false or is not set (the default value is false), the raw notification will trigger the background task after the notification delivery event handler has done its work.
like image 40
David Hayes Avatar answered Oct 22 '22 18:10

David Hayes