Search code examples
c#xamlsilverlightwindows-phonewindows-phone-8.1

Call a third party app via System Launcher to set text to Clipboard


I'm having some trouble trying to understand how to call a third party app on WP8.1 to handle the Clipboard setText method. I know that there isn't an API available at the moment, so this is the method I'm using, I want to get the text from a RichEditBox and send that to the Clipboard.

    private async void copyClipboard_Click(object sender, RoutedEventArgs e)
    {
        String temp;
        myRichEditBox.Document.GetText(TextGetOptions.None, out temp);
        await Windows.System.Launcher.LaunchUriAsync(new Uri(@"clipboard:?Text=" + temp));
    }

This is what happens: I get a message that tells me I need a third party app (and that's ok), I installed Clipboarder from the list of suggested app, but then I reopened my app, I tapped on the button that triggers the method above and nothing happened, I see a transition out and in, like if the OS was trying to open another app (Clipboarder I guess) and then that app crashed and the frame returned to my app. Every time I try that, this always happen. Is there a problem with the Launcher, I mean, am I missing something here?

Thank you for your help :)

Sergio

EDIT: I found a solution, I added that as an answer :D


Solution

  • Ok, I figured it out ahahahahah

    I'll write that here in case anyone else will need this: you just have to install this library.

    https://www.nuget.org/packages/InTheHand.ApplicationModel.DataTransfer/8.2014.4.301

    Then in your app, add something like this:

    var data = new DataPackage();
    data.SetText("My custom text");
    Clipboard.SetContent(data);
    

    Of course you'll have to add a reference to the library in your solution and include it:

    using InTheHand.ApplicationModel.DataTransfer;
    

    Now the app will correctly pass the text to a 3rd party Silverlight app for it to write it in your Clipboard :)