- Home /
How call a Android native class with implements from unity ?
Hi All,
we are creating an application in unity using Android's Eclipse project.
In Eclipse project , we have a class like
package com.unity3d.player;
public class TestProjectActivity extends unityPlayerActivity{
from Unity we are calling the above native class using below code. working perfect
AndroidJavaClass testClass = new AndroidJavaClass("com.unity3d.player.TestProjectActivity");
But, if i have a class like below
public class TestProjectActivity extends UnityPlayerActivity implements ConnectionCallbacks, OnConnectionFailedListener, OnClickListener{
from unity if i call like
AndroidJavaClass testClass = new AndroidJavaClass("com.unity3d.player.TestProjectActivity");
am getting an error,
caused by: java.lang.classnotfoundException: com.unity3d.player.TestProjectActivity
What was the problem ? how to call
public class TestProjectActivity extends UnityPlayerActivity implements ConnectionCallbacks, OnConnectionFailedListener, OnClickListener{
?
can anyone suggest ?
Answer by gfoot · Jan 27, 2014 at 02:15 PM
Try putting a copy of the google-play-services.jar file into your Plugins/Android folder alongside your own code jar file. I haven't used it myself but from the documentation it sounds like this is what they expect you to do.
Answer by VamshiKrishnaP · Jan 28, 2014 at 07:53 AM
@GFOOT , Thanks for the reply. placed google-play-services.jar in Plugins/Android folder along with my code jar file.
the ClassFoundException error was gone.
Now i have to Call a method which is in my Eclipse project
public void sharePhoto(final String textPath, final String imagePath)
{
}
From unity, am calling like
if(GUI.Button (new Rect(150,150,100,50),"Click")){
AndroidJavaClass testClass = new AndroidJavaClass("com.unity3d.player.TestProjectActivity");
testClass.Call<AndroidJavaObject>("sharePhoto","hai Sir","http://stereo.gsfc.nasa.gov/beacon/latest_256/ahead_euvi_195_latest.jpg");
}
am getting an error like
can you help on this ? Thank you in Advance.
Answer by gfoot · Jan 28, 2014 at 09:15 AM
You should post a separate question really, but the answer is that your Java method doesn't return a value so when you call it you should not specify the generic argument. Just call it like this:
testClass.Call("sharePhoto","hai Sir","http://stereo.gsfc.nasa.gov/beacon/latest_256/ahead_euvi_195_latest.jpg");
@gfoot , please refer the question at http://answers.unity3d.com/questions/629672/how-to-call-a-android-native-class-with-implements.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613131627im_/https://answers.unity.com/themes/thub/images/avi.jpg)