Search Unity

  1. Good news ✨ We have more Unite Now videos available for you to watch on-demand! Come check them out and ask our experts any questions!
    Dismiss Notice
  2. Ever participated in one our Game Jams? Want pointers on your project? Our Evangelists will be available on Friday to give feedback. Come share your games with us!
    Dismiss Notice

Application.CaptureScreenshot doesn't work for Tizen

Discussion in 'Tizen' started by nandonandito, May 21, 2017.

  1. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
  2. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    I'm looking this issue.
     
  3. Jaehyun

    Jaehyun

    Unity Technologies

    Joined:
    Feb 4, 2014
    Posts:
    55
    The captured screenshot is stored under Application.temporaryCachePath in Tizen.
    You can copy it to the other path where you want.
    This is a sample code to save the captured file under 'Downloads' folder.
    (You should enable MediaStorage in PlayerSettings->Capabilities to copy a file to Downloads folder.)
    Code (CSharp):
    1. using System.Collections;
    2. using System.Collections.Generic;
    3. using UnityEngine;
    4. using System.IO;
    5.  
    6. public class ScreenCapture : MonoBehaviour {
    7.  
    8.     public void CaptureIt()
    9.     {
    10.         Application.CaptureScreenshot("MyCapture.png");
    11.         System.IO.File.Copy(Path.Combine(Application.temporaryCachePath, "MyCapture.png"), "/opt/usr/media/Downloads/MyTest.png", true);
    12.     }
    13. }
     
    nandonandito likes this.
  4. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    btw, actually i can
    wow thankyou so much.. :D
     
  5. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    hi after i try thats code, actually thats work for capture the game, but the result capture is just go to "/opt/usr/media/Downloads/MyTest.png" but i cant see the image on gallery.. and after i restart my phone the capture image is available on gallery.. but if i open my game and doing screencapture again the last capture is doesnt see on gallery and i must restart my phone to do that.. have you try? thankyou..
     
  6. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    Thanks everyone!
     
  7. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    @nandonandito

    Please use Tizen Plugin for updating contents.

    Code (Boo):
    1. bool
    2. tizenupdatecontent(const char *img_path)
    3. {
    4.     dlog_print(DLOG_DEBUG, LOG_TAG, "%s", img_path);
    5.     int ret = media_content_connect();
    6.     if (ret != MEDIA_CONTENT_ERROR_NONE) {
    7.         dlog_print(DLOG_ERROR, LOG_TAG, "media_content_connect() error %p", ret);
    8.     }
    9.  
    10.     ret = media_content_scan_file(img_path);
    11.     if (ret != MEDIA_CONTENT_ERROR_NONE) {
    12.         dlog_print(DLOG_ERROR, LOG_TAG, "media_content_scan_file() error %p", ret);
    13.     }
    14.  
    15.     ret = media_content_disconnect();
    16.     if (ret != MEDIA_CONTENT_ERROR_NONE) {
    17.         dlog_print(DLOG_ERROR, LOG_TAG, "media_content_disconnect() error %p", ret);
    18.     }
    19.  
    20.     return true;
    21. }
    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour {
    2. #if !UNITY_EDITOR && UNITY_TIZEN
    3.     [DllImport ("updatecontent")]
    4.     private static extern bool tizenupdatecontent(string img_path);
    5. #endif
    6.  
    7.     // Use this for initialization
    8.     void Start () {
    9.  
    10.     }
    11.  
    12.     // Update is called once per frame
    13.     void Update () {
    14.  
    15.  
    16.         if (Input.GetKey(KeyCode.Menu))
    17.         {
    18.             Application.CaptureScreenshot("MyCapture.png");
    19. #if !UNITY_EDITOR && UNITY_TIZEN
    20.             System.IO.File.Copy(Path.Combine(Application.temporaryCachePath, "MyCapture.png"), "/opt/usr/media/DCIM/MyTest.png", true);
    21.             tizenupdatecontent("/opt/usr/media/DCIM/MyTest.png");
    22. #endif
    23.         }
    24. }
    25. }
    please find the file on /Debug/libupdatecontent.so.
     

    Attached Files:

    Last edited: May 23, 2017
    nandonandito likes this.
  8. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    @sukwon-suh where can i get updatecontent dll files? after extract your updatecontent.zip and i just see on the folder src updatecontent.c

    i try to copied updatecontent.c to assets/Plugins/Tizen/libs its still doesnt work. or i must go to Tizen Studio to open that? and build .so plugin?

    i see the manuel at : https://docs.unity3d.com/Manual/PluginsForTizen.html
    but i don't really know how to do that at tizen ide/studio
     
    Last edited: May 23, 2017
  9. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    @nandonandito
    I updated updatecontent.zip.
    please find the file on /Debug/libupdatecontent.so.
     
  10. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    @sukwon-suh i use this to call but still get error if i try to build the project "The type or namespace name `DllImport' could not be found. Are you missing an assembly reference?"

    Code (CSharp):
    1. public class NewBehaviourScript : MonoBehaviour {
    2. #if !UNITY_EDITOR && UNITY_TIZEN
    3.     [DllImport ("updatecontent")]
    4.     private static extern bool tizenupdatecontent(string img_path);
    5. #endif
    6.     // Use this for initialization
    7.     void Start () {
    8.     }
    9.     // Update is called once per frame
    10.     void Update () {
    11.         if (Input.GetKey(KeyCode.Menu))
    12.         {
    13.             Application.CaptureScreenshot("MyCapture.png");
    14. #if !UNITY_EDITOR && UNITY_TIZEN
    15.             System.IO.File.Copy(Path.Combine(Application.temporaryCachePath, "MyCapture.png"), "/opt/usr/media/DCIM/MyTest.png", true);
    16.             tizenupdatecontent("/opt/usr/media/DCIM/MyTest.png");
    17. #endif
    18.         }
    19. }
    20. }
     
  11. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
  12. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    yes @sukwon-suh, i try to build and run but error "The type or namespace name `DllImport' could not be found. Are you missing an assembly reference?"

    where the place you copied the libupdatecontent.so ? is on just at "assets" or "assets/plugins/tizen/libs" ? and is you are using [DllImport ("updatecontent")] or [DllImport ("libupdatecontent")] ?
     
  13. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    error.png
    this is the screenshot of the error i get @sukwon-suh
     
  14. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    I used assets folder.

    upload_2017-5-23_21-30-23.png \

    and use like this.
    [DllImport ("updatecontent")]

    please find attached cs file.
     

    Attached Files:

    nandonandito likes this.
  15. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    Would you please check UNITY version?
    I tested it on Unity 5.6.1f1. (this is the latest)
     
  16. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    thankyou so much @sukwon-suh the plugin is work without error, but the screenshot is still doesn't available if we need to see on gallery.. the screenshot is available on "/opt/usr/media/DCIM" folder but at gallery it doesn't.. i use Tizen Z1 and Z2 to test this. the screenshot will available on gallery if i restart my phone..
     
  17. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    @sukwon-suh i use Unity 5.6.0p1, is i must update my unity?
     
  18. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    @nandonandito
    oops.. you didn't use name space on the c# script.
    please add this.
    using System.Runtime.InteropServices;
     
  19. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    ya.. i forgot the namespace, but after i use the namespace and test it again, it still doesn't see the screenshot on gallery, but this just work if i find at folder.. i will make the video how its looks like
     
  20. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    @sukwon-suh this the video, that i hope can more easier to explain, btw sorry about my english is not really good :)
     
  21. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    Would please attach logs?
    It looks plugin APIs is not called.
     
  22. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39

    Attached Files:

  23. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    @nandonandito
    Please find attached UNITY project.
    I tested it on Z1.
    It works fine on my environment.
     

    Attached Files:

    nandonandito likes this.
  24. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    i must download the new unity version for can open the attached project. btw capture on your phone is work and can open at gallery?
     
  25. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    hi @sukwon-suh thankyou so much for your help, after i find the problem, and i forgot to check contentwriter on capabilities.. i really apreciate that, thankyou so much for help me to solve my problem.. thankyou.. :)
     
  26. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    @nandonandito
    Ah,, I forget to let you know about privileges.

    upload_2017-5-24_9-11-16.png

    upload_2017-5-24_9-11-40.png
     
    nandonandito likes this.
  27. nandonandito

    nandonandito

    Joined:
    Nov 24, 2016
    Posts:
    39
    yep @sukwon-suh , finally you're really help me to solved this problem.. thankyou.. :)
     
  28. creamsonlee

    creamsonlee

    Joined:
    May 23, 2017
    Posts:
    2
    @sukwon-suh 안녕하세요~ 같은 문제가 있어서 이 글을 감사히 참고하였습니다. 추가 질문이 있는데 이 방법을 Unity 5.6.1f1에서 적용했을 땐 잘 되었으나, 유니티5.4.5로 빌드 하고 같은 기기로 테스트를 하면 여전히 휴대폰을 재부팅해야만 갤러리에서 사진을 확인할 수 있었습니다. 유니티 5.4.5버전에서는 이 문제를 해결할 방법이 없을까요?
     
    Last edited: Jun 18, 2017
  29. sukwon-suh

    sukwon-suh

    Joined:
    Mar 31, 2015
    Posts:
    81
    @creamsonlee
    안녕하세요 5.4.5p3 에서 동작하는 샘플 첨부드립니다.
    5.4.x version에 path 지정 오류가 있어서 gallery로 바로 저장하는 샘플을 구현했습니다.
    사용해 보시고 알려주세요.
    감사합니다.

    Hello developer, I made a sample on UNITY 5.4.5p3.
    There is a problem on 5.4.x version, so I made a new sample to save file on gallery path.
    Please let me know your result.
    Thank you.
     

    Attached Files:

  30. creamsonlee

    creamsonlee

    Joined:
    May 23, 2017
    Posts:
    2
    @sukwon-suh 첨부 해 주신 샘플을 제 프로젝트와 비교 해 보며 제가 어떤 부분에서 실수를 했는지 찾았습니다. 바쁘실텐데 직접 샘플까지 만들어 주시다니 감동입니다. 정말 감사합니다!!
     
    Last edited: Jun 20, 2017
unityunity