Exemple #1
0
    public IEnumerator Capture()
    {
        yield return(new WaitForEndOfFrame());

        screenCap.ReadPixels(new Rect(198, 98, 298, 198), 0, 0);
        screenCap.Apply();

        // Encode texture into PNG
        byte[] bytes = screenCap.EncodeToPNG();
        //Object.Destroy(screenCap);

        // For testing purposes, also write to a file in the project folder

        string screenshotFilename = "Green_" + System.DateTime.Now.ToString("yyyy-MM-dd-HHmmss") + ".JPG";

        Application.CaptureScreenshot(screenshotFilename);


        if (Application.platform == RuntimePlatform.Android)
        {
            string myFolderLocation = "/sdcard/DCIM/Asd/";


            if (!System.IO.Directory.Exists(myFolderLocation))
            {
                System.IO.Directory.CreateDirectory(myFolderLocation);
            }

            movePath = myFolderLocation + screenshotFilename;
        }


        filePath = screenshotFilename;

        shot = true;

        ssButton.SetActive(true);
        backButton.SetActive(true);
        testColor.SetActive(true);
        colorButton.SetActive(true);
        Slider_T.SetActive(true);
        Text_t.SetActive(true);
        Slider_S.SetActive(true);
        Text_S.SetActive(true);


        ActiveUrl = movePath;

        // string action = Intent.ACTION_MEDIA_SCANNER_SCAN_FILE
        AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
        string           action      = intentClass.GetStatic <string>("ACTION_MEDIA_SCANNER_SCAN_FILE");

        // Intent intentObject = new Intent(action);
        AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent", action);

        // Uri uriObject = Uri.parse("file:" + filePath);
        AndroidJavaClass  uriClass  = new AndroidJavaClass("android.net.Uri");
        AndroidJavaObject uriObject = uriClass.CallStatic <AndroidJavaObject>("parse", "file://" + movePath);

        // intentObject.setData(uriObject);
        intentObject.Call <AndroidJavaObject>("setData", uriObject);

        // this.sendBroadcast(intentObject);
        AndroidJavaClass  unity           = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
        AndroidJavaObject currentActivity = unity.GetStatic <AndroidJavaObject>("currentActivity");

        currentActivity.Call("sendBroadcast", intentObject);
    }