Wrote this subroutine for taking shots, but it's not working (and doesn't even ask for permissions)
I have written an app and everything works fine. I added a feature which is taking shots from the android phone's screen and there it is:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ScrShot : MonoBehaviour
{
[SerializeField]
public GameObject blink;
public void TakeShot()
{
StartCoroutine("Capture");
}
IEnumerator Capture()
{
string timestamp = System.DateTime.Now.ToString("dd-MM-Y-HH-mm");
string filename = "Armo Shot" + timestamp + ".png";
string path = Application.persistentDataPath + "/" + filename;
ScreenCapture.CaptureScreenshot(path);
yield return new WaitForEndOfFrame();
// Refreshing the android gallery
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://" + path) });
objActivity.Call("sendBroadcast", objIntent);
}
}
It seems to be working, I just linked it to OnClick()
event of a button, but nothing happens when I press that button in the app. It also isn't asking for any permissions for writing files in the internal/external storage.
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220613042433im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Unity UI - Button Slow On Some Devices? 0 Answers
UnsatisfiedLinkError for android library 0 Answers
Was the audio file embed into the scene asset bundle file? 0 Answers
Unity3d on linux for android 0 Answers
Play Store with Unity Personal 1 Answer