9

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: 

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();
    }

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.

If anyone is interested in trying this on their own here is some documentation:

DataTransferManager

DataRequested

DataPackage

GetForCurrentView()

UPDATE

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.

ellemayo
  • 3,258
  • 2
  • 20
  • 30
  • Actually I am also facing the same problem for email attachment I am using this one it crashes at the same point can you give me any idea. – Mohit Apr 27 '13 at 05:36
  • @Mohit, have you tried to use the EmailComposeTask object as described in the answer below? It should be used for sending emails on mobile – ellemayo Apr 29 '13 at 13:19
  • I am trying it but I want to send mail with an Attachment via code. – Mohit Apr 30 '13 at 04:38
  • @Mohit, This is sort of a separate question but I did find some resources on it. Check out these links: http://www.geekchamp.com/articles/send-email-with-attachments-without-using-emailcomposetask-with-mailmessage and http://www.geekchamp.com/marketplace/components/livemailmessage hope that helps – ellemayo May 02 '13 at 13:10
  • Thank you man @ellemayo but I had seen it before it shows me up a pop up every time..:( – Mohit May 03 '13 at 03:46
  • @Mohit, try posting this as a separate SA question, maybe someone with experience using livemailmessage can help you get it working properly – ellemayo May 03 '13 at 15:24
  • I think that DataTransferManager is supported only for windows phone 8.1 xaml runtime apps only. – Mani Apr 29 '15 at 10:38

4 Answers4

10

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.

Here are the functions that I will be implementing

    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();
    }

Ref:

Launchers for Windows Phone

Share Link Task

ellemayo
  • 3,258
  • 2
  • 20
  • 30
2

According to my API reference, DataTransferManager is reserved for native apps only. Windows Phone API Quickstart.

ridoy
  • 6,274
  • 2
  • 29
  • 60
kindasimple
  • 2,427
  • 1
  • 16
  • 20
0

Have you tried using the fully qualified method? It would be something like this:

DataTransferManager dataTransferManager = indows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();

Also, make sure your target is Windows Phone 8.

sadify
  • 132
  • 1
0

The Windows 8 Share Contract isn't supported on WP8. There isn't even a Share charm on WP8. Why are you trying to use the DataTransferManager?

Instead of using the Share Contract, most usecases can work just fine with WP8 app2app custom protocols and file extensions. Using WP8 app you can transfer files and data across apps. Althrough the standardized contract of the Share Contract is gone, apps can create their own contracts using custom protocols and file extensions.

Here for example you can learn more about a real-world 3rd party implementation of Nokia Music custom protocols.

JustinAngel
  • 16,082
  • 3
  • 44
  • 73
  • There may not be a share charm on WP8 but there does appear to be a consistent share view within many (of at least Microsoft's) apps. Clicking share takes you to the same result as the share charm where you choose your sharing method. See it in IE, Photos, Store, Office etc. they all appear to be the same which is similar to the share charm. Since the API appeared to be accessible, I was attempting to send data to it in a similar method as the charm. Thanks for your feedback, I will likely revert to this if I can't find a solution. – ellemayo Nov 29 '12 at 14:26
  • "Share" within each 1st party app is it's own thing and has nothing to do with the Share Contract or DataTransferManager and isn't extensible for the most part. Specific 1st party apps (pictures, camera, etc) expose specific endpoints that 3rd party apps can register to. – JustinAngel Nov 29 '12 at 16:26