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…!!
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…!!
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
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