Is it possible to add some platform-specific code and functionality to a multi-platform UE4 game?
For example, on Android if I want to start another application from inside the game.
Or let’s just say if I want to talk to the Android API’s that are normally used by Android app developers.
Normally an Android app can have both Java code and native (C++) code, so I suppose this should be technically possible.
Adding Android functionality isn’t really the hard part - it’s usually how to get to it from your game. Assuming you are using full source (GitHub) then it’s not hard to add functionality. Here’s how you would add something to Java, let’s call it DoStuff:
Add a DoStuff function to GameActivity.java that you want called from C++
Add a “thunk” method variable in AndroidJNI.h and .cpp, called AndroidThunkJava_DoStuff
In JNI_OnLoad in AndroiJNI.cpp, find the function with GetMethodID and your function signature (something like “(Ljava/lang/String;)V” if your function took a string and returns nothing.
Add a global C++ function to AndroidJNI.cpp called AndroidThunkCpp_DoStuff(const FString&)
Have it call the java method with CallVoidMethod, passing it the string like AndroidThunkCpp_LaunchURL does
Now extern AndroidThunkCpp_DoStuff and call it from wherever you need (this is very game specific)
TL;DR: Look at LaunchURL and how it’s handled in AndroidJNI.cpp and GameActivity.java
Note that I have locally cleaned up some of the JNI code to make it more readable and some other tweaks, so in 4.6 the code you added to AndroidJNI.cpp will need to change a little bit - nothing outlandish tho.