I want to make a screenshot of the Android screen while playing the game by pressing a GUI button and save it to the android's Gallery.
I found a tutorial that details how to save images to the android's gallery using the SDK and java. Here's the link http://developer.android.com/training/camera/photobasics.html
My problem is that I don't understand how to use java with unity. My basic understanding is that I need to either make a library or a plugin. Is that correct? Can you point me to a tutorial that walks me through the process? Or suggest another approach?
After lots of digging, I've found a solution, but it's made me realize that this post probably should have been three separate questions.
RE: How to use Java Plugins in Unity
Second, to view the screenshot from the android file manager, the file path needs to be set using
RE: Android Gallery
I got a partial answer for the 'saving an image in the users gallery on Android' part of the question. That's how we do it in native Android. I will look for a solution from Unity.
This is pretty much copy and paste from one of our previous projects. I removed some of the error handling (you have to check for the existence of the folder etc).
INSERTSOMEVIEWHERE is some view in Android. This code is basically meant to take a screenshot from a particular view ans save it in the gallery. You can take the root view if you want to take a screenshot of the whole app.
There is that external helper function directoryAndStorage.getOrCreatePictureDirectory I use to create a folder in the users gallery depending on which device we are running on (Some devices don't have an external storage and the Nook does not have the function getExternalStoragePublicDirectory). The helper function is far from complete, you could add support for different Android versions aswell:
That's it so far. If you have questions, shoot. I'm going to post updates soon.
You should use this wonderful plugin with full support.
answered Jun 30 at 04:05 PM