locked
Share charm doesn't show all HTML share targets for my app RRS feed

  • Question

  • I have written an app that shares a bitmap and text in HTML, and the share targets that show up do not include the People app.
    I want people to be able to share to the People App.

    It works fine to share to the Mail App.

    Ideas what I may be doing wrong?  The block below is in a file called html.js and it is pointed to right after the default.js file.

    Does it look like I've formed this incorrectly that some targets would not show up when sharing?

    (function () {
        "use strict";
        var page = WinJS.UI.Pages.define("default.html", {
            ready: function (element, options) {
                var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
                dataTransferManager.addEventListener("datarequested", shareHtmlHandler);
                //document.getElementById("shareButton").addEventListener("click", showShareUI, false);
            },
            unload: function () {
                var dataTransferManager = Windows.ApplicationModel.DataTransfer.DataTransferManager.getForCurrentView();
                dataTransferManager.removeEventListener("datarequested", shareHtmlHandler);
            }
        });
    
        function shareHtmlHandler(e) {
            var localImage = "ms-appx:///images/poemchicken.png";
            //I want to use the innerHTML of the DIV with the ID 'htmlFragment'
            var htmlExample = "<table><tr><td><img src=\"" + localImage + "\"></td><td>" + document.getElementById('thePoem').innerHTML + "</td></tr><tr colspan=2><td><p><a href='http://apps.microsoft.com/windows/en-US/app/haiku-chicken/8a80ef0b-fba2-409d-a3c6-f5e6977fd96c'>made with Haiku Chicken</a></td></tr>";
            //var htmlExample = "<p>Here is a local image: <img src=\"" + localImage + "\">.</p>";
            var request = e.request;
            request.data.properties.title = "A poem from Haiku Chicken";
            request.data.properties.description =
                "Haiku Chicken and your friends have written you a poem.";
            var htmlFormat =
                Windows.ApplicationModel.DataTransfer.HtmlFormatHelper.createHtmlFormat(htmlExample);
            request.data.setHtmlFormat(htmlFormat);
            var streamRef =
                Windows.Storage.Streams.RandomAccessStreamReference.createFromUri(new Windows.Foundation.Uri(localImage));
            request.data.resourceMap[localImage] = streamRef;
        }
    
    
        function showShareUI() {
            Windows.ApplicationModel.DataTransfer.DataTransferManager.showShareUI();
        }
    })();


    --Scott.

    Saturday, January 12, 2013 9:08 PM

Answers

  • Hi Scott,

    The Windows Store app allows you to define the sharing function with two contracts:

    The sharing source contract
    The sharing target contract

    #Sharing and receiving content (Windows Store apps using JavaScript and HTML) (Windows)
    http://msdn.microsoft.com/en-us/library/windows/apps/Hh758314.aspx

    In your case, your app is going to share data to other app, then you need to implement the sharing source contract and supply the data to share (the formats you want to support in your app) as you've already done. However, whether other application will accept data (or accept what kinds of data) from your app (or other app which also supply data to share) depends on the developer of that app. In this case, you cannot control the sharing target behavior of the "People" application.

    You can download the "sharing source" sample and try share various data and watch how "People" app will show in the target app list (when you change the data type to share):

    #Sharing content source app sample
    http://code.msdn.microsoft.com/windowsapps/Sharing-Content-Source-App-d9bffd84

    based on my test, the "People" app will appear when I choose to share "link" or "html" data. But when I actually click the "People" app, it says it failed to get the share data. And that's the behavior on my local test machine and  it is totally depending on the People app's implementation.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.


    Monday, January 14, 2013 6:33 AM
    Moderator