How to use Background agent to send toast notification? - windows-phone-7

I am working on windows development & I am displaying the items on the emulator by using a web service.
Now I want to send a toast notification when an item added to the service. Already I worked with push notifications. But It’s generating push channel URL when app is initialized.
I don’t want to use this channel URL. So I tried Background Agent & Shell Toast to send the notification. Its working fine for static data. How can I add dynamic data to back ground agent which is coming from web service?
One more thing is, there are two things like PeriodicTask & ResourceIntensiveTask. How can I use this to send a toast notification by using Background Agent?

You can refer to this Tutorial From Nokia
http://developer.nokia.com/community/wiki/How_to_create_simple_Background_Agent_in_Windows_Phone
and this from CodeProject
http://www.codeproject.com/Articles/656654/Windows-Phone-Background-Agent-Part-Periodic-T

Related

Windows Phone 7.5 - Push Notifications when app is tombstoned

I have written a Windows 7.5 phone app that registers for tile and toast push notifications with MPNS. I have all the infrastructure working and the phone registers with MPNS. I save the ChannelUri locally on the phone and then post the ChannelUri to a rest service endpoint on my website which records the device / ChannelUri. I'm able to send toast and tile messages from the web service and receive them on the phone without any problem. If the application is running I'm able to trap the ShellToastNotificationReceived event and can read the push notification details and I save the message to a local database in the application and the messages are also displayed to the user in a Listbox. The system is disconnected from my website other than having to register the ChannelUri and all the data I need is contained with the notification.
My question is when the application has been tombstoned and I send a push notification I see a toast message displayed by the phone OS and if I click on the toast I have put a URI pointing to a page in my application and this re-launchs the app and I can trap all the data in the message and can save it again to the database. But if the application is tombstoned and the user misses the toast I have no way of saving that message it is lost unless I write some logic to go back to my server and check if the messages I have locally match the ones it sent. Am I missing something or am I going to have to run a check with my server when the app re-launches and re-sync with my server for any toast push notifications the user might have missed.
Thanks
When a push notification is received while the application is not running or is tombstoned there is no way to handle the data if nothing was done with the missed toast. You might need confirmation logic on the server to check whether the message is received or not.

Windows Phone 7 - Is it possible to add additional key/values to push notifications messages

I'm testing out Windows Phone 7.5 push notifications. I have got the 3 different push types working fine (Toast, Tile and Raw) and am able to send messages from unit tests and a web application without any problems and receive them in my WP application. I want the ability to add extra properties to the push notification and the Raw push type does this perfectly for me and I can add custom key/value pairs or anything else to the push message and extract it on the phone app. I have just found out however that it only works if the application is running and my unit tests fail (suppressed notification status is received in unit test) when the phone application is not running (checked documentation which confirms this too). Is there anyway to add extra properties (key/values) to toast or tile messages or some way I can use raw in another way ? Toast notifications seem limited to a title property and an actual message property but I need to add additional data.
Just wondering if anyone had any suggestions / workarounds ?
The general practice I use is to initially send a raw notification to the device with phone-usable data embedded in the message. If my application is currently running then I can process the contents of the raw message and immediately make use of it on the phone. However if the application is not currently running on the phone you will receive notification from the push servers that the message could not be delievered. If I receive this response I send out a Toast / Tile notification.
With Toast notifications the only parametrisation you have access to is the URI that will launch the application. This is specified with the wp:param node of the message. Eg.
<wp:Notification xmlns:wp="WPNotification">
<wp:Toast>
<wp:Text1>Toast Title</wp:Text1>
<wp:Text2>Toast sub title</wp:Text2>
<wp:Param>/MainPage.xaml?LaunchedFrom=A%20Toast%20Notification</wp:Param>
</wp:Toast>
</wp:Notification>
If the user taps on this toast notification your application will launch and navigate to MainPage.xaml. You can access the querystring passed in via the NavigationContext.QueryString.
Note: The wp:Param node can only be sent to Mango (and up) devices. Additionally the entire contents must be less than 256 characters or you'll receive a PushErrorTypeMessageBadContent error. (Thanks to Ritch Melton for pointing this out). More info available from the Sending Push Notifications for Windows Phone page on MSDN.
As you've discovered, the Microsoft Push Notification Service is very strict in what types of messages you can send and receive. The intent of these push notifications is to provide simple push updates and not large amounts of data. The flexible Raw type seems like it would fit the bill until you discover that:
You can use a raw notification to send information to your application. If your application is not currently running, the raw notification is discarded on the Microsoft Push Notification Service and is not delivered to the device.
However, if you send a toast notification to your application, when the user clicks on the toast the application is started. When your application starts, you should check a service and retrieve the data you are trying to send from a web-service or other remote mechanism.

Is there a way to check for missed/unread notifications?

Is there an api in mango sdk that allows me to programatically poll the notifications/toast to at least get the count. I'd like to write background service check for missed messages.
It's not possible to get hold of the email/SMS messaging details like this in Windows Phone. The only way to interact with the email client is via the SDK Launchers and Choosers: see this link on MSDN.
About all you can do is call the EmailComposeTask or SmsComposeTask for writing a plain text email or SMS, or EmailAddressChooserTask for getting an email address from the address book.
Also bear in mind that launchers and choosers must be initiated by a user action and cannot be launched from any background agent code.

Using Microsoft Push Notification Service with Window Phone

I am thinking of a simple chat application in Window Phone using Microsoft Push Notification Service.
I read a guide at http://msdn.microsoft.com/en-us/library/hh202967(v=VS.92).aspx which talks about creating a client application that receive toast notification.
This is a first time for me to develop a mobile application so I do not get some part of it.
The question that I have is, is it possible for a client (window phone) to send toast notification directly to other client? I have found below image from the web. It seems that I need to have Cloud Application(probably webserver?) to play with notification service.
Would it be possible to build a Window phone application that directly request to MPNS to send notification to other window phone application? (so from the picture above, '2' will directly point to Microsoft Push Notification Service)
If it is not, what is the reason for that?
There is a good explanation of the push notification service here.
From the above link.
Registration Phase 2: Now that the MPNS known the presence of the
phone on the network, it is required the phone itself provide the Uri
to the Earthquake service. Until this not happen the service doesn't
know there is a phone that need to be notified so it is not able to
provide the notifications. The phone must call a method on the
Earthquake service to provide the Uri that has been answered by the
MPNS. Once the Earthquake service gets this url it can store this
informations somewhere for a later use.
In your case you'll need communication between your devices before any notifications can be sent. This is to know the uri of your phone. A server has to store these uris for all devices registered for notifications. This is why you'll need an application which sends the xml to the MPNS.

Animate application icon in windows phone

I have tried googling for this and came up empty. What I want is a tutorial or example code of how to change my icon on the windows phone like the people application or SMS. For example when you get a new SMS message it puts a number next to the face in the icon. Is there any way for me to do that in my app?
You need to send a Tile Push Notification.
This allows you to update the image, text and (optionally) a number.
Push notifications shoudl be triggered from a remote [web] service.
You can also have the tile update periodically using a ShellTileSchedule.
You can update your application's Tile using Push Notifications from a web service registered with a Microsoft Push Notification Service. However, this isn't absolutely necessary. You can even update your tiles without push notifications, by setting a ShellTileSchedule. The minimum update interval is 1 hour, however.
See here.

Resources