For my game I want to import and export levels the player has made in the editor.
I’ve figured out how to do the export from Application.persistentDataPath to Dropbox/gallery using Intents, but cannot seem to find how to receive an image using Intents.
As far as I can tell so far, the basics is the same, but instead of ACTION_SEND I use ACTION_GET_CONTENT, but I have no idea where the image is then sent. All examples I find are for native Android apps and those seem to call a function when an image is selected, but I’m unsure how to deal with this on Android.
Could someone provide some insight?
[edit]
So far I seem to need to find out how to call startActivityForResult instead of startActivity, and where/how to override onActivityResult. Everything I find is people writing plugins for Unity, but I’d like to keep it to C# scripts. If I can use intents, then this must be possible too right?
What I have so far:
void OnMouseDown(){
AndroidJavaClass intentClass = new AndroidJavaClass ("android.content.Intent");
AndroidJavaObject intentObject = new AndroidJavaObject ("android.content.Intent");
intentObject.Call<AndroidJavaObject> ("setType", "image/png");
intentObject.Call<AndroidJavaObject> ("setAction", intentClass.GetStatic<string> ("ACTION_GET_CONTENT"));
AndroidJavaClass unity = new AndroidJavaClass ("com.unity3d.player.UnityPlayer");
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject> ("currentActivity");
currentActivity.Call ("startActivityForResult",
intentObject.Call<AndroidJavaObject>(intentClass.CallStatic( "createChooser", intentObject, "Select picture")),
intentClass.GetStatic<string> ("SELECT_IMAGE"));
}
void onActivityResult(string resultData){
//?
}