Click here to Skip to main content
Click here to Skip to main content

How to Share Status from WP7 using the ShareStatusTask?

By , 26 Apr 2012
 

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)

About the Author

_ Kunal Chowdhury _
Software Developer
India India
Member
Kunal Chowdhury is a Microsoft MVP (Most Valuable Professional) in Silverlight Technology, a Codeproject MVP & Mentor, DZone MVB (Most Valuable Blogger), Speaker in various Microsoft events, Author, passionate Blogger and a Software Engineer by profession.
 
He is currently working as a Software Engineer II in an MNC located at Pune, India. He has a very good skill over XAML, C#, Silverlight and WPF. He has a good working experience in Windows 7 application (including Multi-touch) development too.
 
He posts his findings in his technical blog. He also writes for SilverlightShow and Codeproject portal. Many of his articles were highlighted as "Article of the Day" in Microsoft sites.
 
He also has another website called Silverlight-Zone.com where he posts article links on Silverlight, Windows Phone 7 and XNA accumulated from various web sites to help the community grow on specified technologies.
 
You can reach him in his Blog : http://www.kunal-chowdhury.com
He is also available in Twitter : http://twitter.com/kunal2383

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
Hint: For improved responsiveness ensure Javascript is enabled and choose 'Normal' from the Layout dropdown and hit 'Update'.
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
-- There are no messages in this forum --
Permalink | Advertise | Privacy | Mobile
Web04 | 2.6.130516.1 | Last Updated 27 Apr 2012
Article Copyright 2012 by _ Kunal Chowdhury _
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid