How to Share Status from WP7 using the ShareStatusTask?
Do you want to develop an application or game which will update your status or game result in some social networking sites like Facebook, Tw...- Article authored by Kunal Chowdhury on .
Do you want to develop an application or game which will update your status or game result in some social networking sites like Facebook, Tw...- Article authored by Kunal Chowdhury on .
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.
“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.
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.
CodeProjectThank you for visiting our website!
We value your engagement and would love to hear your thoughts. Don't forget to leave a comment below to share your feedback, opinions, or questions.
We believe in fostering an interactive and inclusive community, and your comments play a crucial role in creating that environment.