- Home /
Apply texture to object from device gallery
I'm using this code which allows me to open the gallery and select a picture.
public void OpenAndroidGallery()
{
#region [ Intent intent = new Intent(); ]
//instantiate the class Intent
AndroidJavaClass intentClass = new AndroidJavaClass("android.content.Intent");
//instantiate the object Intent
AndroidJavaObject intentObject = new AndroidJavaObject("android.content.Intent");
#endregion [ Intent intent = new Intent(); ]
#region [ intent.setAction(Intent.ACTION_GET_CONTENT); ]
//call setAction setting ACTION_SEND as parameter
intentObject.Call<AndroidJavaObject>("setAction", intentClass.GetStatic<string>("ACTION_GET_CONTENT"));
#endregion [ intent.setAction(Intent.ACTION_GET_CONTENT); ]
#region [ intent.setData(Uri.parse("content://media/internal/images/media")); ]
//instantiate the class Uri
AndroidJavaClass uriClass = new AndroidJavaClass("android.net.Uri");
//instantiate the object Uri with the parse of the url's file
AndroidJavaObject uriObject = uriClass.CallStatic<AndroidJavaObject>("parse", "content://media/internal/images/media");
//call putExtra with the uri object of the file
intentObject.Call<AndroidJavaObject>("putExtra", intentClass.GetStatic<string>("EXTRA_STREAM"), uriObject);
#endregion [ intent.setData(Uri.parse("content://media/internal/images/media")); ]
//set the type of file
intentObject.Call<AndroidJavaObject>("setType", "image/jpeg");
#region [ startActivityForResult(intent , 1); ]
//instantiate the class UnityPlayer
AndroidJavaClass unity = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
//instantiate the object currentActivity
AndroidJavaObject currentActivity = unity.GetStatic<AndroidJavaObject>("currentActivity");
//call the activity with our Intent
currentActivity.Call("startActivity", intentObject);
#endregion [ startActivityForResult(intent , 1); ]
}
I also know how to apply the texture (using WWW). What I'm missing is the URL for the picture that is selected. I have the pathway but because the picture is selected in runtime, I can't insert the image name.
Can anyone help me to access the pathway and image name during runtime so I can apply it as a texture?
Comment