Click here to Skip to main content
Click here to Skip to main content
Technical Blog

How to Share Status from WP7 using the ShareStatusTask?

, 26 Apr 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
Do you want to develop an application or game which will update your status or game result in some social networking sites like Facebook, Twitter, Linked-In and/or Windows Live? Then this post will help you to integrate such task in your app.   Using “ShareStatusTask” of the Windows Phone 7 SDK, y

Do you want to develop an application or game which will update your status or game result in some social networking sites like Facebook, Twitter, Linked-In and/or Windows Live? Then this post will help you to integrate such task in your app.

Using "ShareStatusTask" of the Windows Phone 7 SDK, you can update your status line on the social networking sites. Continue reading the post for more details of the API and the implementation steps.

Know About the API

"ShareStatusTask" is a sealed class present in the namespace "Microsoft.Phone.Tasks" and inherits the class named "ShareTaskBase". ShareStatusTask exposes a string property called "Status" where you will set the message that you want to share on social networking sites.

Here is the meta data of the ShareStatusTask:

 
namespace Microsoft.Phone.Tasks
{
    public sealed class ShareStatusTask : ShareTaskBase
    {
        public string Status { get; set; }
    }
}

Let’s see how the class is actually implemented. The class internally creates two properties named "MePublishType" and "PSM". The status message sets as a string value to the internal property "PSM".

Here is the SDK code of the "ShareStatusTask" class, check out the implementation:

namespace Microsoft.Phone.Tasks
{
  public sealed class ShareStatusTask : ShareTaskBase
  {
    public string Status { get; set; }
 
    internal override ParameterPropertyBag BuildParameterPropertyBag()
    {
      ParameterPropertyBag parameterPropertyBag = new ParameterPropertyBag();
      parameterPropertyBag.CreateProperty("MePublishType").Int32Value = 0;
      parameterPropertyBag.CreateProperty("PSM").StringValue = this.Status;
      return parameterPropertyBag;
    }
  }
}

Here is the decompiled version of the ShareTaskBase:

namespace Microsoft.Phone.Tasks
{
  public abstract class ShareTaskBase
  {
    public void Show()
    {
      if (!ChooserHelper.NavigationInProgressGuard((Action) (() => this.Show())))
        return;
      ChooserHelper.Navigate(new Uri(this.BuildUri(), UriKind.Absolute), 
                                                this.BuildParameterPropertyBag());
    }
 
    internal abstract ParameterPropertyBag BuildParameterPropertyBag();
 
    internal virtual string BuildUri()
    {
      return "app://5B04B775-356B-4AA0-AAF8-6491FFEA5615/MePublish";
    }
 
    internal enum MePublishType
    {
      PSM,
      UT,
      LINK,
      CHECKIN,
    }
  }
}

From the above code you can see that the base class "ShareTaskBase" exposes the Show() method, when called opens the client screen to share the status. "MePublishType" is a enum which consists of 4 values and sets the publish type.

Implementation Steps

Let’s see how to integrate this task in your application or game. You have to first create the instance of ShareStatusTask class and set the property "Status" with the message that you want to share in social networking sites before calling the Show() method.

Here is the code snippet of the same:

var shareStatusTask = new ShareStatusTask();
shareStatusTask.Status = "ShareStatusTask Demo: " +
                         "Checkout www.kunal-chowdhury.com for articles on WP7";
shareStatusTask.Show();

Remember that, the application will be able to share to social networking sites of their own choice depending on the sites they have synched their devices with.

As it is not possible to configure social networking sites in Windows Phone 7 emulator, hence I am not able to take snapshot of how it looks when you call the Show() method. Try it out in your device to see it in action.

I hope that this post was very useful for you to understand the SDK API, it’s internal code implementation and the sample code implementation. Please leave your feedback below to leave your comment. Follow my blog to read more articles on Windows Phone 7.

Stay tuned to my blog, twitter or facebook to read more articles, tutorials, news, tips & tricks on various technology fields. Also Subscribe to our Newsletter with your Email ID to keep you updated on latest posts. We will send newsletter to your registered email address. We will not share your email address to anybody as we respect privacy.

Reference: http://www.kunal-chowdhury.com
You may like to follow me on twitter @kunal2383 or may like the Facebook page of my blog http://www.facebook.com/blog.kunal2383.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

_ Kunal Chowdhury _
Technical Lead
India India
Kunal Chowdhury is a Microsoft "Client Development" MVP (Most Valuable Professional), a Codeproject Mentor, Telerik MVP, Nokia Developer Champion, Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.
 
He is currently working in an MNC located in India. He has a very good skill over XAML, C#, Silverlight, Windows Phone, WPF and Windows 8 (WinRT). He posts his findings, articles in his technical blog and CodeProject.
 
Technical Blog: http://www.kunal-chowdhury.com
Facebook: http://facebook.com/blog.kunal
Twitter : http://twitter.com/kunal2383
Follow on   Twitter   Google+   LinkedIn

Comments and Discussions

 
-- There are no messages in this forum --
| Advertise | Privacy | Mobile
Web03 | 2.8.141015.1 | Last Updated 27 Apr 2012
Article Copyright 2012 by _ Kunal Chowdhury _
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid