从 Windows Phone 8 共享 [英] Sharing from Windows Phone 8
问题描述
我正在开发 Windows Phone 8 应用程序并尝试通过 DataTransferManager 共享内容.Windows API 文档说它在 Windows Phone 中受支持,但是当调用 DataTransferManager.GetForCurrentView()
函数时,我得到一个异常
I am working on a Windows Phone 8 app and am trying to share content through the DataTransferManager. The Windows API documentation says it is supported in Windows Phone but when the DataTransferManager.GetForCurrentView()
function is called I get an exception
System.NotSupportedException was unhandled by user code
HResult=-2146233067
Message=Specified method is not supported.
Source=Windows
InnerException:
我一直在寻找答案,但找不到其他有同样问题的人,任何帮助将不胜感激.有关此主题的所有示例似乎都特定于 Windows 8,但 Phone 8 确实包含这些功能.这是我的应用中的示例代码.
I have been searching for an answer and can't find anyone else with the same issue, any help would be appreciated. All samples on this topic seem to be Windows 8 specific, but Phone 8 does include these functions. Here's sample code from my app.
protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
{
DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(dataTransferManager_DataRequested);
}
private void dataTransferManager_DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
{
DataPackage requestData = e.Request.Data;
requestData.Properties.Title = "Share Text Example";
requestData.Properties.Description = "An example of how to share text.";
requestData.SetText("Hello World!");
}
private void Button_Tap_1(object sender, System.Windows.Input.GestureEventArgs e)
{
DataTransferManager.ShowShareUI();
}
同样,当页面在 DataTransferManager.GetForCurrentView();
函数上加载时会显示异常,因此它不会到达其他行,但无论如何都包含它们.我试过添加/删除权限和程序集,但肯定缺少一些东西.我也试过把这个函数放在不同的事件中(比如 onTap 函数),结果是一样的.
Again, the exception is shown when the page loads on the DataTransferManager.GetForCurrentView();
function so it doesn't get to the other lines, but included them anyway. I've tried adding/removing permissions and assemblies but must be missing something. I've also tried putting the function in different events (such as the onTap function) with the same results.
如果有人有兴趣自己尝试,这里有一些文档:
更新
尽管鉴于此问题的上下文,它可能不是最佳解决方案,但我正在执行如下所述的电子邮件/短信/链接任务,而不是使用 DataTransferManager.似乎 DataTransferManager 可能无法在 WP8 中访问,尽管任务将采用许多不同的功能,但它们似乎是执行预期功能的最佳方式.
Although it may not be the best solution given the context of this question, I am implementing the Email/Sms/Link Tasks as described below rather than using the DataTransferManager. It seems that DataTransferManager may not be accessible in WP8 and although the tasks will take a number of different functions they seem to be the best way to perform the intended functionality.
推荐答案
我想我已经通过 Launchers 找到了我想要的大部分内容......我不仅可以使用 Windows 8 通用共享功能,还可以使用 Tasks/启动器.
I think I have found most of what I was looking for with Launchers... Rather than just using the Windows 8 general sharing functionality I can be specific with Tasks/Launchers.
不幸的是,它没有魅力那么多的共享选项,我将实现电子邮件/短信/社交的几个功能,但到目前为止这是最好的解决方案.
Unfortunately it doesn't have as many sharing options as the charm does, I will be implementing several functions for email/sms/social but so far this is the best solution.
这是我将要实现的功能
private void ShareLink(object sender, System.Windows.Input.GestureEventArgs e)
{
ShareLinkTask shareLinkTask = new ShareLinkTask()
{
Title = "Code Samples",
LinkUri = new Uri("http://msdn.microsoft.com/en-us/library/windowsphone/develop/ff431744(v=vs.92).aspx", UriKind.Absolute),
Message = "Here are some great code samples for Windows Phone."
};
shareLinkTask.Show();
}
private void ShareEmail(object sender, System.Windows.Input.GestureEventArgs e)
{
EmailComposeTask emailComposeTask = new EmailComposeTask()
{
Subject = "message subject",
Body = "message body",
To = "recipient@example.com",
Cc = "cc@example.com",
Bcc = "bcc@example.com"
};
emailComposeTask.Show();
}
private void ShareSMS(object sender, System.Windows.Input.GestureEventArgs e)
{
SmsComposeTask smsComposeTask = new SmsComposeTask()
{
Body = "Try this new application. It's great!"
};
smsComposeTask.Show();
}
参考:
这篇关于从 Windows Phone 8 共享的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!