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

Refreshing android gallery to show immediately saved photo

Discussion in 'Android' started by ZeroGravityr, Dec 8, 2016.

  1. ZeroGravityr

    ZeroGravityr

    Joined:
    Mar 19, 2015
    Posts:
    2
    I made a simple app for android devices that uses mobile's camera to take a photo and save it in internal storage folder /mnt/sdcard/DCIM/Camerizeman/

    Photos are saved correctly but the problem that i am faceing is that i can't see the photos from mobile's gallery. I can see them correctly if i use a file manager or reboot me device. i am searchig 10 days now and the problem is that i have to refresh the gallery after saving the image.

    I didn't found any working solution.

    my code is bellow:

    Camera mainCamera;
    RenderTexture renderTex;
    Texture2D screenshot;
    Texture2D LoadScreenshot;
    int width =Screen.width; // for Taking Picture
    int height =Screen.height; // for Taking Picture
    string fileName;
    string myScreenshotLocation;
    string screenShotName ="MyImage_AR_"+System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss")+".png";

    publicvoidSnapshot(){
    StartCoroutine(CaptureScreen());
    }

    publicIEnumeratorCaptureScreen(){
    yield returnnull;
    UI//GameObject.FindGameObjectWithTag("Snapshoot").SetActive(false);
    yield returnnewWaitForEndOfFrame();

    if(Screen.orientation ==ScreenOrientation.Portrait||Screen.orientation ==ScreenOrientation.PortraitUpsideDown){
    mainCamera =Camera.main.GetComponent<Camera>();// for Taking Picture
    renderTex =newRenderTexture(width, height,24);
    mainCamera.targetTexture = renderTex;RenderTexture.active = renderTex;
    mainCamera.Render();
    screenshot =newTexture2D(width, height,TextureFormat.RGB24,false);
    screenshot.ReadPixels(newRect(0,0, width, height),0,0);
    screenshot.Apply();//falseRenderTexture.active =null;
    mainCamera.targetTexture =null;
    }

    if(Screen.orientation ==ScreenOrientation.LandscapeLeft||Screen.orientation ==ScreenOrientation.LandscapeRight){
    mainCamera =Camera.main.GetComponent<Camera>();// for Taking Picture
    renderTex =newRenderTexture(height, width,24);
    mainCamera.targetTexture = renderTex;RenderTexture.active = renderTex;
    mainCamera.Render();
    screenshot =newTexture2D(height, width,TextureFormat.RGB24,false);
    screenshot.ReadPixels(newRect(0,0, height, width),0,0);
    screenshot.Apply();//falseRenderTexture.active =null;
    mainCamera.targetTexture =null;
    }

    myScreenshotLocation = myFolderLocation + screenShotName;File.WriteAllBytes(myFolderLocation + screenShotName, screenshot.EncodeToPNG());}
     

    Attached Files:

  2. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    31
    Im having the same problem after doing a file copy to the Camera folder . Did you manage to resolve this? Its something to do with file refresh but I havent found a good solution yet. Thanks A
     
  3. DeveshPandey

    DeveshPandey

    Joined:
    Sep 30, 2012
    Posts:
    212
    In Android , you have to write native code to refresh gallery, otherwise not possible.
     
  4. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    31
    Hi Davesh do you or anyone know of a script that exists? TY
     
  5. DeveshPandey

    DeveshPandey

    Joined:
    Sep 30, 2012
    Posts:
    212
  6. artofmining

    artofmining

    Joined:
    May 1, 2016
    Posts:
    31
    Thanks Dev .. I'll take a look !
     
unityunity