1
我想從Unity發送數據到我的android插件的java。如何從Unity發送值並以Java接收我的插件?
這裏是我的統一編碼:
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");
}
這裏是我的Java代碼:
public void EnableAds(int qwe)
{
Log.i(APP_TAG, "Value" + qwe);
}
錯誤:
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)
個部隊密切..
該應用程序工作正常,如果我在我的Java代碼中刪除從EnableAdv(INT QWE)int參數..
誰能告訴我在這段代碼丟失,什麼事兒IM。 ?
的統一標記是微軟團結不要濫用它 –
。 **我找到了答案.. ** 我想用「(J)V」作爲我的參數類型..但是替代這個我不喜歡使用「(I)V」 **例如,** Java方法: long f(int n,String s,int [] arr); 具有以下類型signa (ILjava/lang/String; [I)V「 – MicroEyes
請發佈您的搜索結果作爲答案,並在幾小時後接受它。問候, –