I wants to send data from Unity to java for my android plugin.
Here’s my Unity Code:
AndroidJNI.AttachCurrentThread();
IntPtr cls_Activity = AndroidJNI.FindClass("com/unity3d/player/UnityPlayer");
IntPtr fid_Activity = AndroidJNI.GetStaticFieldID(cls_Activity, "currentActivity", "Landroid/app/Activity;");
IntPtr obj_Activity = AndroidJNI.GetStaticObjectField(cls_Activity, fid_Activity);
Debug.Log("Setup Objects Complete");
IntPtr cls_OurAppNameActivityClass = AndroidJNI.FindClass("org/plugin/test/AdmobTestActivity");
IntPtr startAdsMethod = AndroidJNI.GetMethodID(cls_OurAppNameActivityClass, "EnableAds", "(J)V");
Debug.Log("before If Loop");
if (AndroidJNI.IsInstanceOf(obj_Activity, cls_OurAppNameActivityClass) != false)
{
//Debug.Log("Activity IS a OurAppNameActivity");
jvalue[] myArray = new jvalue[1];
myArray[0] = new jvalue();
myArray[0].i = 12;
AndroidJNI.CallVoidMethod(obj_Activity, startAdsMethod, myArray);
Debug.Log("Activity Leaving a OurAppNameActivity");
}
Here’s My Java Code:
public void EnableAds(int qwe)
{
Log.i(APP_TAG, "Value" + qwe);
}
ERRORS:
05-16 13:11:30.906: W/dalvikvm(12315): threadid=8: thread exiting with uncaught exception (group=0x40018578)
05-16 13:11:30.921: E/AndroidRuntime(12315): FATAL EXCEPTION: GLThread 9
05-16 13:11:30.921: E/AndroidRuntime(12315): java.lang.NoSuchMethodError: EnableAds
05-16 13:11:30.921: E/AndroidRuntime(12315): at com.unity3d.player.UnityPlayer.nativeRender(Native Method)
05-16 13:11:30.921: E/AndroidRuntime(12315): at com.unity3d.player.UnityPlayer.onDrawFrame(Unknown Source)
05-16 13:11:30.921: E/AndroidRuntime(12315): at android.opengl.GLSurfaceView$GLThread.guardedRun(GLSurfaceView.java:1368)
05-16 13:11:30.921: E/AndroidRuntime(12315): at android.opengl.GLSurfaceView$GLThread.run(GLSurfaceView.java:1123)
AND FORCE CLOSE..
This Applications is working fine if i removed int argument from EnableAdv(int qwe) in my java code..
Can anyone tell me, what thing i m missing in this code.?
I found the answer..
I want using “(J)V” as my argument type.. but instead of this i shud to use “(I)V”.
For example, the Java method:
long f (int n, String s, int[] arr);
has the following type signature:
“(ILjava/lang/String;[I)V
Refer this for further reading