- Home /
How to add/edit onActivityResult for the activity created by currentActivity
Hi all,
I have a problem that not being able to set the onActivityResult(int requestCode, int resultCode, Intent data) for the "currectActivity created in C#(Unity).
In Unity I have the code like this :
private AndroidJavaObject ajo;
void Start()
{
AndroidJavaClass jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
ajo = jc.GetStatic<AndroidJavaObject>("currentActivity");
ajc.CallStatic ("playVideo");
}
From C# I call this method in Java:
private void playVideo() {
....
startActivityForResult(intent, REQUEST_FOR_RESLUT);
}
However, because I do not know how to set the onActivityResult() method for the activity in C#, the startActivityForResult is just like a startActivity. I cannot get any callback from onActivityResult() .
I would appreciate if you can provide any help. Thanks.
Answer by liortal · Sep 11, 2016 at 01:22 AM
onActivityResult is a callback method that is called when an activity you started returns with some value.
What you should do:
Create your own custom activity class (see details on how to do that in this link: https://docs.unity3d.com/Manual/PluginsForAndroid.html). Specifically, look for the section named "Extending the UnityPlayerActivity Java Code".
In the activity you create, you should handle the onActivityResult callback method. Add whatever handling code you need (e.g: call back into Unity using UnitySendMessage, or whatever handling you need.
Your answer
Follow this Question
Related Questions
How to use AndroidJavaClass.Call() to pass a ArrayList or Array 1 Answer
How to use AndroidJavaClass.Call() to pass a data object 1 Answer
using shared libraries generated by Android project in Unity 0 Answers
AndroidJavaObject.Call fails with 'method not found' 1 Answer
SEGV_ACCERR issue in java plugin 1 Answer