Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

UE4.19 Call to Java method crashes GearVR app no error on log

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)

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++?

Product Version: UE 4.19
more ▼

asked Apr 20 '18 at 08:51 AM in C++ Programming

avatar image

1 2 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

1 answer: sort voted first

For anyone having the same issue, I managed to find out what was wrong. When calling the Java method I had not instantiated an object of the class before doing so. This caused it to crash - the lack of an error is what really made it difficult to find. This is how I fixed it:

 jmethodID classConstructor = FJavaWrapper::FindMethod(Env, Class, "<init>", "()V", false);
 jobject classObject = Env->NewObject(Class, classConstructor, "()V");

First line finds the no arguments constructor method for the class, and second line instantiates the object. Before this you do have to have found the class, activity and Env. After getting the object you can call methods from the class. No need to change anything in Unreal source code.

more ▼

answered Apr 23 '18 at 02:34 PM

avatar image

1 2 5

(comments are locked)
10|2000 characters needed characters left
Viewable by all users
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question