Problem to send an Activity as parameter

54 views
Skip to first unread message

Victor Riascos

unread,
Feb 24, 2014, 9:44:17 AM2/24/14
to google-adm...@googlegroups.com

Hi guys!

I have a problem sending a variable of type Activity from C# to Java.

The following source code is what I did in C#:

  1. public static string TestJava()
  2.     {
  3.         string somestring = "";
  4.         playerClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
  5.         activity = playerClass.GetStatic<AndroidJavaObject>("currentActivity");
  6.         pluginClass = new AndroidJavaClass("com.Vector3GameStudio.GoogleMobileAds.GoogleMobileAdsActivity");
  7.         try
  8.         {
  9.             pluginClass.CallStatic("Test", activity );
  10.         }
  11.         catch (Exception e)
  12.         {
  13.             somestring += "ERROR invoking Test" + e.Message;
  14.         }
  15.         return somestring;
  16.     }
And the following source code is the Java method who it will recieve the Activity.
  1. public static void Test(Activity currentActivity)
  2. {
  3.         // Doesn't get here at all
  4. }

If I change the parameter Activity in the Java method by String, int and so on, the code works well but if I change it by an Activity, the java invocation doesn't work. To check what is wrong in my code I print the exception message, obtaining the following message:

Tetsjava.lang.NSuchMethodError: no static method match with name='Test' signature='(Loomunity3d.player.UnityPlayerActivity;)V' in class 

Could someone help me with that?

Thank you in advance!

Eric Leichtenschlag

unread,
Feb 24, 2014, 8:47:31 PM2/24/14
to google-adm...@googlegroups.com
Hi Victor,

AdMob actually has an open-source unity plugin. You can see how it was implemented here. Your code looks pretty similar to the plugin. Are you sure it's not just a typo or something with the class name?

Thanks,
Eric

Victor Riascos

unread,
Feb 26, 2014, 11:26:01 AM2/26/14
to google-adm...@googlegroups.com
Hi Eric,

Do you have an Unity3D project working with that plugin? I used the plugin but It didn't work :S

By the way, How do you send an Activity from Unity to Java? :D

Greetings!

Eric Leichtenschlag

unread,
Feb 26, 2014, 8:14:30 PM2/26/14
to google-adm...@googlegroups.com
What didn't work about it? Did you run it on device? Did you add the prefab? Did you include the SDK as a dependency? Do the logs indicate that the plugin even got started executing? I'd be happy to take a look at your project if you sent it over.

Here is how the plugin passes the Activity to the plugin.

Cheers,
Eric

Victor Riascos

unread,
Feb 27, 2014, 9:41:30 AM2/27/14
to google-adm...@googlegroups.com
Hi Eric,

I uploaded my project in: Advertising Unity3D Android Plugin.zip

In that file there are the ADT projects and the Unity3D project, and this is the exception when the plugin is deployed in the Android device.


Maybe the error is something really silly, but I'm really rockie in this kind of projects :S

Thank you so much Eric for your support!

Eric Leichtenschlag

unread,
Feb 27, 2014, 12:58:11 PM2/27/14
to google-adm...@googlegroups.com
Hi Victor,

When running your project as sent, I was getting lots of errors saying it couldn't find google play services classes. In your project, you're only referencing google-play-services_lib.jar. Instead, you'll want to just dump the entire google-play-services_lib/ folder into Plugins/Android. I also uncommented the com.google.android.gms.version meta-data tag in your manifest. Then I was able to run it without errors, so I'm assuming it worked.

Cheers,
Eric
Reply all
Reply to author
Forward
0 new messages