Using unreal 4.19.1, I am trying to implement a Java method to launch a different app from mine. I have a java class with the method in [project]/Build/Android/src/com/[company]/[project]
The same method works perfectly well when called from a native Android app built in Android Studio. I had to adapt it a little for Unreal, but the call remains almost the same.
public void launchOther(Context act, String pkgName)
{
Intent launchIntent = new Intent();
launchIntent = act.getPackageManager().getLaunchIntentForPackage(pkgName);
if (launchIntent != null)
{
act.startActivity(launchIntent);
}
}
I call it in game from a function that I coded in c++ and exposed to blueprint so that I can easily call it from a widget.
I know it gets to the method call because I have added debug logs in between every step until the java class call, and they all print as expected.
[2018.04.20-08.07.51:499][371]LogTemp: Display: Getting Env
[2018.04.20-08.07.51:500][371]LogTemp: Display: Getting Activity
[2018.04.20-08.07.51:500][371]LogTemp: Display: Getting Class
[2018.04.20-08.07.51:501][371]LogTemp: Display: Getting Method
[2018.04.20-08.07.51:501][371]LogTemp: Display: Getting Intent
Those are the last lines of the log, there is no error, no crash, nothing, it simply stops. I know it isn’t the code for the method, because commenting the code out and leaving the method empty inside still has the same behavior. This is the line where it stops in c++:
Env->CallVoidMethod(Launcher, launchMethod, Activity, jPkgName);
I know the class and the method get found because I check if the previous step succeeded before going to the next step, and those errors generate a Critical Error on the log - I fixed those already. I use TCHAR_TO_ANSI(*pkgName) to pass an FString from the blueprint function to the Method. I want to add some sort of log to the java class, but haven’t figured out a way to do it yet.
Any thoughts on what could be causing the crash? Or maybe a better way to launch a different Android app? Or a better way to call a Java method from c++?