Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by ShraddhaP · Dec 04, 2017 at 06:55 AM · saveapplicationgallerytocapturescreenshot

How can I take screenshot in an unity application and save it to device's gallery (for android and ios both)?

I have done with this screenshot but it does not save into mobile's gallery application but it is there where the apk build is being installed.

Any help would be appreciated. Thanks in advance..!!

Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

2 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by ShraddhaP · Dec 05, 2017 at 10:04 AM

 IEnumerator CRSaveScreenshot() 
 { 
     yield return new WaitForEndOfFrame();
     // string TwoStepScreenshotPath = MobileNativeShare.SaveScreenshot("Screenshot" + System.DateTime.Now.Hour + System.DateTime.Now.Minute + System.DateTime.Now.Second);
     // Debug.Log("A new screenshot was saved at " + TwoStepScreenshotPath);
 
      string myFileName = "Screenshot" + System.DateTime.Now.Hour + System.DateTime.Now.Minute + System.DateTime.Now.Second + ".png";
      string myDefaultLocation = Application.persistentDataPath + "/" + myFileName;
      string myFolderLocation = "/storage/emulated/0/DCIM/Camera/JCB/";  //EXAMPLE OF DIRECTLY ACCESSING A CUSTOM FOLDER OF THE GALLERY
      string myScreenshotLocation = myFolderLocation + myFileName;
 
      //ENSURE THAT FOLDER LOCATION EXISTS
      if (!System.IO.Directory.Exists(myFolderLocation))
      {
          System.IO.Directory.CreateDirectory(myFolderLocation);
      }
 
      ScreenCapture.CaptureScreenshot(myFileName);
      //MOVE THE SCREENSHOT WHERE WE WANT IT TO BE STORED
 
      yield return new WaitForSeconds(1);
 
      System.IO.File.Move(myDefaultLocation, myScreenshotLocation);
 
      //REFRESHING THE ANDROID PHONE PHOTO GALLERY IS BEGUN
      AndroidJavaClass classPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
      AndroidJavaObject objActivity = classPlayer.GetStatic<AndroidJavaObject>("currentActivity");
      AndroidJavaClass classUri = new AndroidJavaClass("android.net.Uri");
      AndroidJavaObject objIntent = new AndroidJavaObject("android.content.Intent", new object[2] { "android.intent.action.MEDIA_MOUNTED", classUri.CallStatic<AndroidJavaObject>("parse", "file://" + myScreenshotLocation) });
      objActivity.Call("sendBroadcast", objIntent);
      //REFRESHING THE ANDROID PHONE PHOTO GALLERY IS COMPLETE



Comment
Add comment · Show 3 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShraddhaP · Dec 05, 2017 at 10:05 AM 1
Share

This is the complete code by which we can take snapshots and save to Android Gallery. Let's not try the random Plugins ;D Cheers

avatar image Eemil_Ahonen · Mar 08, 2018 at 05:06 PM 0
Share

Taking a screenshot and moving it works if waitforseconds is greater than 2. And the refreshing the android gallery doesn't work. It just gives a big error

avatar image hollym16 · Nov 26, 2020 at 04:20 PM 0
Share

Hi @ShraddhaP @Ginxx009 Thank you for this, I really didn't want to use a plugin so it's great to see a script that deals with it easily. I've copied this script and when I run it, it saves the initial image but doesn't move it to the DCI$$anonymous$$/Camera folder. I get an error saying:

 UnauthorizedAccessException: Access to the path "/storage/emulated/0/DCI$$anonymous$$/Camera/JCB/" is denied.

In my Android $$anonymous$$anifest I have the permissions:

   <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.WRITE_INTERNAL_STORAGE" />
   <uses-permission android:name="android.permission.READ_INTERNAL_STORAGE" />

Any ideas what's going wrong here? Thanks

avatar image
1

Answer by Ginxx009 · Dec 04, 2017 at 07:23 AM

The documentation of Unity includes a page describing plugins. Under the Android section, there is a description of how to make a jar file and use AndroidJavaObject to access it in Unity. RE: How to make and save an Android Screenshot First, according to this this post , androids have problems encoding to PNG. This postprovided a link to an alternative jpg encoding. Second, to view the screenshot from the android file manager, the file path needs to be set using Application.persistentDataPath . More in this post. RE: Android Gallery After taking a screenshot, the image does not show up in the gallery regardless of the filepath. However, on rebooting the phone, it does a media scan and automatically adds all image files to the gallery, again regardless of the filepath. This post about forcing a media scan, but I have yet to try out the answer

Comment
Add comment · Show 11 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image ShraddhaP · Dec 04, 2017 at 09:39 AM 0
Share

I have tried this using easy mobile plugin, the screenshots do not appear in the mobile's gallery.

avatar image Ginxx009 ShraddhaP · Dec 04, 2017 at 09:42 AM 1
Share

did you try this one

 using UnityEngine;
 using System.Collections;
 
 public class showscreenshot : $$anonymous$$onoBehaviour {
 void On$$anonymous$$ouseDown() {
 Application.CaptureScreenshot("Screenshot.png");
 }
 }

lets try it as a code . If it works tell me so we can proceed to the next step . Lets not use a Plugin . hahaha

avatar image ShraddhaP Ginxx009 · Dec 04, 2017 at 10:16 AM 0
Share

Done Lol ;p Now...? Can we move to internal or personal thread?

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

73 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

How to save a screenshot to the camera roll (picture gallery)? 3 Answers

[WP8] Application.CaptureScreenshot() image not shown in gallery 0 Answers

Taking Screenshot on Android.. 1 Answer

Android Native Screenshot function creats black Image 1 Answer

Screenshot is not saving to Gallery and folder 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges