SOLVED[check post below]
Hi community,
Im looking for help overhere, currently im working on puzzle game. And right now im working on feature that allow’s user to load image from gallery and then i will generate puzzle from that same file. But i cant get it working, maybe someone of you could help me a bit.
This part of code [Written in Eclipse/Java], should get picked image path from gallery and send it to unity player. It’s working with this, but this doesn’t returns “real” image path:
It returns something like this: “content://media/external/images/media/4642”
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(resultCode == RESULT_OK)
{
Uri selectedImage = data.getData();
UnityPlayer.UnitySendMessage("Main Camera", "OpenImage", selectedImage.toString());
}
}
I found this solution below and it seems that it should be working, but it’s not. It just crash my game when i try to run it:
public void openGallery()
{
Intent intent = new Intent(Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI);
startActivityForResult(intent, 1);
}
public void onActivityResult(int requestCode, int resultCode, Intent data)
{
if(resultCode == RESULT_OK)
{
Uri selectedImage = data.getData();
UnityPlayer.UnitySendMessage("Main Camera", "OpenImage", getRealPathFromURI(selectedImage));
}
}
public String getRealPathFromURI(Uri contentUri) {
// can post image
String [] proj={MediaStore.Images.Media.DATA};
Cursor cursor = managedQuery( contentUri,
proj, // Which columns to return
null, // WHERE clause; which rows to return (all rows)
null, // WHERE clause selection arguments (none)
null); // Order-by clause (ascending by name)
int column_index = cursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
cursor.moveToFirst();
return cursor.getString(column_index);
}
I tried a lot of other solutions but all of them just crash the game. I tried to load image to Bitmap and then convert bitmap to string and send it to unity player. But it always crash, and i think it’s because i’m not getting the “real” path for image. Any ideas?