Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

How to Share Status from WP7 using the ShareStatusTask?

0.00/5 (No votes)
26 Apr 2012 1  
How to share status from WP7 using the ShareStatus task

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 an 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 a 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, its 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 has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here