Push tweets to a Windows Phone 7 device (via push notifications)
After reading about how simple it was to push notifications over to a Windows Phone device from Sgt.Conkers article, I dug out some old codes from my archives. I had previously written some codes to retrieve a user’s mentions/replies from Twitter over an interval and to push these tweets as notifications via Prowl to the iPhone. I changed some codes and made it to push to the Microsoft Push Notification Service instead. So,once that message goes to the Service, it’ll push that message to the Windows Phone device.

To make this happen, I have small desktop app which runs and polls twitter on an interval for any new mentions/replies for the user logged on. What’s needed is the :
- Twitter account username
- Twitter account password
- Notification URI to the Windows Phone device (more on this in a bit)

Not forgetting that we also need the actual client application on the Windows Phone device to receive the push notifications. To receive notifications, we need to create a Notification Channel so here we say that we need to have a channel created, and if it already exists then just find it from it’s name.
string channelName = "www.skeevs.com";
HttpNotificationChannel channel;
try
{
channel = new HttpNotificationChannel(channelName);
channel.ChannelUriUpdated +=
(s, e) =>
{
Debug.WriteLine(e.ChannelUri.ToString());
};
channel.Open();
channel.BindToShellNotification();
}
catch (NotificationChannelExistsException )
{
channel = HttpNotificationChannel.Find(channelName);
Debug.WriteLine(channel.ChannelUri.ToString());
}
The Channel URI is important since this will be the destination URI for the push notifications from the service, which directly indicates the Windows Phone device. Once the application is running on the emulator, the ‘output’ window in your VS2010 IDE will contain the Channel URI. This URI highlighted below is the URI that is entered into the desktop app mentioned above.

You can give it a test by mentioning the @user and should then see the notification appear on the emulator. I’m wondering how is it possible to have the notification message wrap nicely on the screen.
It would probably be easier to see it working for yourself, so I’ve included the source code to this demo : WP7PushTweets.zip
There are 2 folders in the zip:
- WP7PushTest – Silverlight client application for the Windows Phone.
- WP7PushTweets – Desktop application that retrieves the user’s tweets.
References


Recent Comments