Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Tier 2 - question about Android java callbacks

Author
Message
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 15th May 2014 21:02
I'm finally making the move to t2 as I really need more functionality out of t1 than I can get. I've got the template all set up and working.
I'm wondering if any T2 programmers are using their own functions to call java methods. I've looked up how to do callbacks and it is a bit beyond me. So if someone out there has an example I'd love to see it!

bjadams
AGK Backer
16
Years of Service
User Offline
Joined: 29th Mar 2008
Location:
Posted: 16th May 2014 01:04
i tried to integrate the Fmod music system and failed miserably on android.

on ios and windows 2 all worked fine!
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 16th May 2014 01:07
Oh I'm not looking at anything that complex. I just want to add in some commands for various Android SDKs.

east
11
Years of Service
User Offline
Joined: 4th Apr 2013
Location:
Posted: 16th May 2014 06:49 Edited at: 16th May 2014 07:37
Did you mean calling java function from native code and calling native function from java code using JNI?
If yes i think i have the example you want (I integrate google play leaderboard and admob interstitial in my last T2 project).
However, right now i am a bit busy because my newest project is in the finishing stages so I'm only able to give you a few pointer right now.

If you're looking to implement google play leaderboards in T2 projects you should look at this example: https://github.com/playgameservices/android-samples

Fore some JNI example, take a look at the Endless Tunnel project. Open the Tunnel directory and you will find jni directory. You might want to look at these files: jni_util, java_bgnactivity, java_ouractivity (both .cpp and .hpp) and the headers file in java_headers directory. I base my jni implementation from this project.

You will need to make a few changes though if you want to use these code in your agk project.

First you need to create your own launcher activity (AGK use nativeactivity by default)



and make changes on the manifest file so it launch this activity instead of NativeActivity then put the java function that you want to call in this activity class.



And in the jni_util files i make some changes so it can works in AppGameKit project:



And as how to call the java function from native code, take a look at bgn_activity.cpp file. In short, it goes like this:



I think those are the important points to call java function from native code, i hope i don't miss anything important Calling native function from java code is more complicated though.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 16th May 2014 08:12
This is pretty much exactly what I'm looking for and explained in a way that I can mostly understand it. Thank you!!

I won't need to call native code from java that I can think of, but I will need to get data back from the java methods. Got any examples of that? If not that's OK because I'm a ways off from getting even this far. I have a bit to learn about C++ first.

east
11
Years of Service
User Offline
Joined: 4th Apr 2013
Location:
Posted: 16th May 2014 10:57 Edited at: 16th May 2014 11:15
Sure, here is some example to get the return value;


In the example above, the getApiLevel returns int value. In case you need to get the String type or pass a string parameter, here is some example:



One thing to point is that "(II)I", "()V", "(Ljava/lang/String;Ljava/lang/String; )Ljava/lang/String;" and "(Ljava/lang/String;I)V" is the format of parameter and return type of the function. "()V" means void method with no parameter, "(II)I" is int method with two int parameter and "(Ljava/lang/String;Ljava/lang/String; )Ljava/lang/String;" is string method (string is an object in java) with 2 string parameter. Here is some explanation about it: http://www.cab.u-szeged.hu/WWW/java/tutorial/native1.1/implementing/method.html

And all the example above is if you call a function from your activity class. I don't have the example if you want to call a static method, etc.
Naphier
13
Years of Service
User Offline
Joined: 2nd Oct 2010
Location: St Petersburg, Florida
Posted: 16th May 2014 20:41

Login to post a reply

Server time is: 2024-04-20 02:18:49
Your offset time is: 2024-04-20 02:18:49