Search Unity

Problem with Univeral app 8.1 (10) share charm and screenshot

Discussion in 'Windows' started by BigFI, Oct 9, 2015.

  1. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    Hello,

    I'm trying to share a screenshot of my end game through the share charm of the universall app.

    So I'm able right now to share text via the datatransfer manager like explained here :
    https://msdn.microsoft.com/en-us/library/windows/apps/xaml/hh871368.aspx?f=255&MSPPError=-2147217396

    But I'm unable to share an image with that.

    I first use the Application.CaptureScreenshot("screen.png"). After that, I try to reload it in a storagefile, convert it in a RandomAccessStreamReference to use it with the SetBitmap.

    But I always have an error. Since I move to Win10+VS2015, I'm unable to see the c# in visual studio so I don't have the error.

    Has somebody done this before and can share his method?

    Thank you in advance.

    Karim
     
  2. Ignas83

    Ignas83

    Unity Technologies

    Joined:
    Mar 26, 2013
    Posts:
    28
    What do you mean by you can't see C# in vs2015? Which files can't you see exactly? Sharing a code snippet of your attempt might also help.
     
  3. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    Yes, sorry for that. I forgot to copy that before coming to work. I will put my code as soon as I come home.

    Maybe a I misunderstood. But when you build your universal app and check the C# option, you can open your project in VS and see the C# files?
     
  4. Ignas83

    Ignas83

    Unity Technologies

    Joined:
    Mar 26, 2013
    Posts:
    28
    Of course you can. But you mentioned in the first post that something stopped working with vs2015 so I got confused. Anyway, let's see your code.
     
  5. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    Here is my code.

    First I use the capturescreenshot

    Code (CSharp):
    1. Application.CaptureScreenshot("background.png");
    And after, the user click a buton to share it

    Code (CSharp):
    1. public void ShareButton()
    2.     {
    3.         UnityEngine.WSA.Application.InvokeOnUIThread(() =>
    4.         {
    5.            
    6. #if NETFX_CORE
    7.                 DataTransferManager dataTransferManager = DataTransferManager.GetForCurrentView();
    8.                 dataTransferManager.DataRequested += new TypedEventHandler<DataTransferManager, DataRequestedEventArgs>(this.DataRequested);
    9.  
    10.                 Windows.ApplicationModel.DataTransfer.DataTransferManager.ShowShareUI();
    11. #endif
    12.         }, false);
    13.  
    14.     }
    15.  
    16. #if NETFX_CORE
    17.     private async void DataRequested(DataTransferManager sender, DataRequestedEventArgs e)
    18.     {
    19.     try{
    20.         DataRequest request = e.Request;
    21.         request.Data.Properties.Title = "My highscore in Cemetery Rush";
    22.         request.Data.Properties.Description = "An example of how to share text.";
    23.         request.Data.SetText("Woop woop");
    24.  
    25.         Windows.Storage.StorageFile sampleFile = await ApplicationData.Current.LocalFolder.GetFileAsync("background.png");
    26.        
    27.        
    28.         request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(sampleFile));
    29.     }
    30.     catch (Exception ex)
    31.     {
    32.       Debug.Log(ex.Message);
    33.     }
    34.     }
    35.  
    36.  
    37. #endif
    The code share all the text but not the image
     
  6. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,917
    Did you check that backround.png is really saved to Local folder? Try provide absolute path for ex., Application.CaptureScreenshot(Path.Combine(Windows.Directory.localFolder, "background.png"));
     
  7. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    Thank you Tomas for the advice.

    Windows.Directory is not a Win store name space.

    But I tried with

    Code (CSharp):
    1. Application.CaptureScreenshot(Path.Combine(ApplicationData.Current.LocalFolder.Path, "background.png"));
    to save, and I still use

    Code (CSharp):
    1.  Windows.Storage.StorageFile sampleFile = await ApplicationData.Current.LocalFolder.GetFileAsync("background.png");
    2.        
    3.         request.Data.SetBitmap(RandomAccessStreamReference.CreateFromFile(sampleFile));
    to open it.

    But it's still not working.
     
  8. Tomas1856

    Tomas1856

    Unity Technologies

    Joined:
    Sep 21, 2012
    Posts:
    3,917
    Could you copy paste the error message?
     
  9. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    Tomas,

    I don't have any error.
    I just display the path of where the screenshot is saved and what I get for the sampleFile.

    The screen is saved at
    and it's open after. The sampleFile path is
    Sorry I didn't do the test before. So the file with this configuration, is open. But not display in Facebook, mail or Twitter.
     
  10. Ignas83

    Ignas83

    Unity Technologies

    Joined:
    Mar 26, 2013
    Posts:
    28
    I've tried your code sample and it worked fine with Mail. The only thing that went wrong was that Unity failed to capture screenshot but I fixed that. Can you confirm that Background.png file is actually created?
     
  11. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    What did you do to fix it?

    The file exist because I open it with getfileasync.
     
  12. Ignas83

    Ignas83

    Unity Technologies

    Joined:
    Mar 26, 2013
    Posts:
    28
    Hm, could you share your project? Because the code that you pasted works fine in my test project. Or you need to find a way to give us exact error :)
     
  13. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    Ok, that's weird.

    I have no error. Every thing go well. It's just that I don't have the image after the share.

    I'm away on vacation for a week. Will try a dummy project when I come back. Thanks for your help.
     
  14. BigFI

    BigFI

    Joined:
    Dec 14, 2014
    Posts:
    9
    Ok, I did a simple test.

    I tested it on Windows 10 (Universal app 8.1) and it worked.

    So the bug is only on Windows phone 8.1.
     
  15. EricBeets

    EricBeets

    Joined:
    Aug 30, 2017
    Posts:
    9
    Hy There,

    I can share the image by email, but if I tried using Skype, I've got only the text .. (And the share UI does not show FaceBook ..)

    Any idea ?