Unreal access to the PixoVR Platform
Loading...
Searching...
No Matches
PPlatformSubsystem.cpp
Go to the documentation of this file.
1// Copyright 2023 PixoVR Corp. All Rights Reserved.
2
3
5
6DEFINE_LOG_CATEGORY_STATIC(LogPPlatformSubsystem, Log, All);
7
8#define Log(pmt, ...) UE_LOG(LogPPlatformSubsystem, Log, TEXT(pmt), ##__VA_ARGS__)
9#define Warn(pmt, ...) UE_LOG(LogPPlatformSubsystem, Warning, TEXT(pmt), ##__VA_ARGS__)
10#define Error(pmt, ...) UE_LOG(LogPPlatformSubsystem, Error, TEXT(pmt), ##__VA_ARGS__)
11#define Fatal(pmt, ...) UE_LOG(LogPPlatformSubsystem, Fatal, TEXT(pmt), ##__VA_ARGS__)
12
15{
16#if PLATFORM_ANDROID
17 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
18 {
19 jclass JavaClassClass = Env->FindClass("java/lang/Class");
20 jmethodID JavaGetClassNameMethod = Env->GetMethodID(JavaClassClass, "getName", "()Ljava/lang/String;");
21 jstring JavaActivityClassID = (jstring)Env->CallObjectMethod(FJavaWrapper::GameActivityClassID, JavaGetClassNameMethod);
22 const char* GameActivityClassName = Env->GetStringUTFChars(JavaActivityClassID, 0);
23 Log("Assigned Java functions for class %s", GameActivityClassName);
24 Env->ReleaseStringUTFChars(JavaActivityClassID, GameActivityClassName);
25
26 LaunchApplicationFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_IsPackageInstalled", "(Ljava/lang/String;)Z", false);
27 IsApplicationInstalledFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_LaunchPackage", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Z", false);
28 }
29#endif
30}
31
32bool UPPlatformSubsystem::IsApplicationInstalled(const FString& ApplicationName)
33{
34 bool bResult = false;
35#if PLATFORM_ANDROID
36 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
37 {
38 auto PackageNameArg = FJavaHelper::ToJavaString(Env, ApplicationName);
39 bResult = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, FJavaWrapper::AndroidThunkJava_IsPackageInstalled, *PackageNameArg);
40 }
41
42 Log("UPPlatformSubsystem::IsApplicationInstalledFunction: %d", bResult);
43#endif
44 return bResult;
45}
46
47bool UPPlatformSubsystem::LaunchApplication(const FString& ApplicationName, const FString& ExtraKey, const FString& ExtraValue)
48{
49 bool bResult = false;
50#if PLATFORM_ANDROID
51 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
52 {
53 auto ApplicationNameArg = FJavaHelper::ToJavaString(Env, ApplicationName);
54 auto ExtraKeyArg = FJavaHelper::ToJavaString(Env, ExtraKey);
55 auto ExtraValueArg = FJavaHelper::ToJavaString(Env, ExtraValue);
56 bResult = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, FJavaWrapper::AndroidThunkJava_LaunchPackage, *ApplicationNameArg, *ExtraKeyArg, *ExtraValueArg);
57 }
58
59 Log("UPPlatformSubsystem::LaunchApplication: %s, %s : %s", *ApplicationName, *ExtraKey, *ExtraValue);
60#endif
61 return bResult;
62}
63
64
65#undef Fatal
66#undef Error
67#undef Warn
68#undef Log
DEFINE_LOG_CATEGORY_STATIC(LogPPlatformSubsystem, Log, All)
#define Log(pmt,...)
bool IsApplicationInstalled(const FString &ApplicationName)
UFUNCTION(BlueprintCallable, Category = "Pixo Platform")
bool LaunchApplication(const FString &ApplicationName, const FString &ExtraKey, const FString &ExtraValue)
UFUNCTION(BlueprintCallable, Category = "Pixo Platform")