Search Unity

How to Refresh Picture Into Android Gallery

Discussion in 'Scripting' started by hizral, Nov 2, 2015.

  1. hizral

    hizral

    Joined:
    Apr 27, 2010
    Posts:
    568
    Hello All,

    Trying to make my app work here, I manage to make my app take picture using my Android devices, after taking picture the picture will be stored into specific folder that been created. But the problem right now is how do I let the picture that I've taken can be seen from Android Gallery.

    Below here is what I've done so far:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using System.IO;
    4.  
    5. public class CameraFunction : MonoBehaviour {
    6.  
    7.     public int screenShotCount;
    8.     public string screenShotFileName = "";
    9.     public string transfer = "";
    10.     public string transfer2 = "";
    11.  
    12.     public RaycastHit hit;
    13.     public Camera guiCam;
    14.  
    15.     public bool pressed;
    16.  
    17.     // Use this for initialization
    18.     void Start ()
    19.     {
    20.         if (!System.IO.Directory.Exists ("mnt/sdcard/DCIM/UISCREENSHOT/"))
    21.         {
    22.             System.IO.Directory.CreateDirectory ("mnt/sdcard/DCIM/UISCREENSHOT/");
    23.         }
    24.     }
    25.    
    26.     // Update is called once per frame
    27.     void LateUpdate ()
    28.     {
    29.         var ray = guiCam.ScreenPointToRay (Input.mousePosition);      
    30.        
    31.         if (Input.GetMouseButtonUp (0))  //Returns true during the frame the user touches the object
    32.         {
    33.             if (Physics.Raycast (ray, out hit, 100))
    34.             {  
    35.                 if (hit.collider.tag == "camera")
    36.                 {
    37.                     pressed = true;
    38.  
    39.                     do
    40.                     {
    41.                         screenShotCount++;
    42.                         screenShotFileName = "UIscreenShot" + screenShotCount + ".png";
    43.                     }
    44.                    
    45.                     while (System.IO.File.Exists (screenShotFileName));
    46.                     Application.CaptureScreenshot (screenShotFileName);
    47.                 }
    48.             }
    49.         }
    50.  
    51.         transfer = "mnt/sdcard/Android/data/com.LCGDI.ARKARNIVAL2015/files/" + screenShotFileName;
    52.         transfer2 = "mnt/sdcard/DCIM/UISCREENSHOT/" + screenShotFileName;
    53.         System.IO.File.Move (transfer, transfer2);
    54.  
    55.  
    56.     }
    57.  
    58.  
    59. }
     
  2. Marceta

    Marceta

    Joined:
    Aug 5, 2013
    Posts:
    177