For android it’s easy :
In JME project create some interface
public interface MobileNativeInterface{
public void doNativeStuff();
}
then still on JME side, in your main application (the one extending SimpleApplication)
public class MyApp extends simpleApplication{
...
MobileNativeInterface mobile;
public void setMobileNativeInterface(MobileNativeInterface mobile){
this.mobile = mobile;
}
....
public void doNativeStuff(){
mobile.doNativeStuff();
}
....
}
then still on JME side at some point call your native stuff, from where ever you want as long as you have a reference to the app (pass it, or use an AppState)
app.doNativeStuff();
then on the android side, in the MainActivity in the onCreate() method
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState); //don't forget this
//give the mobile interface to the app (app is a MainActivity attribute holding the reference to the JME app)
app.setMobileNativeInterface(new MobileNativeInterface(){
public void doNativeStuff(){
//here you have to be careful, remember the android activity and the JME app
//run on 2 different threads so you have to somehow synchronize them
//else you may get into some threading issues, especially if you want to update
//something on the android ui thread
runOnUiThread(new Runnable() {
public void run() {
actuallyDoYourNativeStuff();
}
});
}
});
}
Note that I inlined the MobileNativeInterface for the sake of the example, you can make a separate class or even hove your MainActivity implements the interface and provide the doNativeStuff method.
That’s all for android.
However for Ios it might be trickier. I never tried Ios deployment so I can’t really answer. The idea is probably the same as it’s simple delegate pattern, but since all java code is compiled into native code, I’m not sure how you would give the MobileNativeInteface implementation to the JME app.
Thanks Normen. I’m new to objective C so this may not be the correct way to do it but it works.
I added a native method based on the ShowDialog example and I then create an instance of JmeAppDelegate and then I can call methods within that. That was so I can interact with native GUI controls and the root view controller.
JNIEXPORT void JNICALL
Java_JmeAppHarness_showIOSLoginScreen(JNIEnv* e, jobject c) {
jmeAppDelegate *myInstance = [[jmeAppDelegate alloc]init];
[myInstance showIOSLoginScreen];
}
This calls the native method inside the XCODE project and in turn has access to all fields and methods in there for native GUI interaction.