I use Application.CaptureScreenshot to get screenshot, that uses Application.persistentDataPath per documentation. It saves the screenshot to the app’s local
files folder. I use
FileProvider to provide screenshot to further services, all works fine.
But when I add the following permissions to the AndroidManifest.xml…
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
…the screenshot goes to the external storage automatically, and it makes FileProvider broken, as there is no more screenshot in the app’s local
files folder (I need external storage permission for an entirely other feature).
Is there any chance to save screenshot to the local folder anyway? Any documentation that shed me a light on the backgrounds?
Well, it does. By default it is on the application’s
files folder, as soon as I claim permissions for external storage, it gets replaced to application’s external (!)
files folder. Would be great to have this documented, or any chance to alter this behaviour, since it has implicit consequences when someone use
Application.CaptureScreenshot for example.
@eppz: I use the following code. It always returns the internal path regardless of the value of the WRITE_EXTERNAL_STORAGE permission.
#if UNITY_ANDROID && !UNITY_EDITOR
using (AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
using (AndroidJavaObject currentActivity = jc.GetStatic<AndroidJavaObject>("currentActivity"))
path = currentActivity.Call<AndroidJavaObject>("getFilesDir").Call<string>("getCanonicalPath");
What I’m looking for is your way of sharing an image without these permissions. Can you post your code or maybe bundle it into a zip file?