hello forum! here we go again!
now i try to call a custom java method just for learning purpose, from another post i see this can be only archived with source code!
i follow this: https://answers.unrealengine.com/questions/104948/platform-specific-functionality-in-ue4-game.html
but i really dont know what is wrong with my code
lets go step by step:
first i modify the GameActivity.java, i add this custom method inside based in AndroidThunkJava_LaunchURL(String URL):
// This is JAVADABADU code
//importing this in order to use Toast
import android.widget.Toast;
public void AndroidThunkJava_Toast(String Msg)
{
try
{
Toast.makeText(getApplicationContext(), Msg, Toast.LENGTH_SHORT).show();
}
catch (Exception e)
{
Log.debug("Toast failed with exception " + e.getMessage());
}
}
now edit too the AndroidJNI.h/cpp files in order to call my java function:
i add jmethodID AndroidThunkJava_Toast variable in both h/cpp as example!
inside FJavaWrapper::FindClassesAndMethods i find the new method as follows: AndroidThunkJava_Toast = FindMethod(Env, GameActivityClassID, “AndroidThunkJava_Toast”, “(Ljava/lang/String;)V”, bIsOptional);
and finally this is my new cpp method:
void AndroidThunkCpp_Toast(const FString& Msg)
{
if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
{
jstring Argument = Env->NewStringUTF(TCHAR_TO_UTF8(*Msg));
FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GameActivityThis, FJavaWrapper::AndroidThunkJava_Toast, Argument);
Env->DeleteLocalRef(Argument);
}
}
now the last step is this, in order to call i declare a new static void inside FJavaWrapper called callToast(const FString& Msg);
and this is the cpp
void FJavaWrapper ::callToast(const FString& Msg)
{
AndroidThunkCpp_Toast(Msg);
}
this is the sad think, i managed to call this from a editor project from custom blueprintFunctionLibrary, but dont work and i dont know why!, i try to call another method, so inside callToast i call AndroidThunkCpp_LaunchURL, and dont work too, but if i call AndroidThunkCpp_Vibrate, vibrate function indeed works jajajaja so i have a cool vibrator phone!,
the question is why my custom function and AndroidThunkCpp_LaunchURL dont work??? is killing me!
please some help here!