Documentation for the Unreal C++ Plugin
Loading...
Searching...
No Matches
PixoLauncherSubsystem.cpp
Go to the documentation of this file.
1// Copyright 2023 PixoVR Corp. All Rights Reserved.
2
3
5#include "GenericPlatform/GenericPlatformMisc.h"
6
7DEFINE_LOG_CATEGORY_STATIC(LogPixoLauncherSubsystem, Log, All);
8
9#define Log(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Log, TEXT(pmt), ##__VA_ARGS__)
10#define Warn(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Warning, TEXT(pmt), ##__VA_ARGS__)
11#define Error(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Error, TEXT(pmt), ##__VA_ARGS__)
12#define Fatal(pmt, ...) UE_LOG(LogPixoLauncherSubsystem, Fatal, TEXT(pmt), ##__VA_ARGS__)
13
19
20void UPixoLauncherSubsystem::Initialize(FSubsystemCollectionBase& Collection)
21{
22#if PLATFORM_ANDROID
23 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
24 {
25 IsApplicationInstalledFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_IsPackageInstalled", "(Ljava/lang/String;)Z", false);
26 LaunchApplicationFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_Launch", "(Ljava/lang/String;[Ljava/lang/String;[Ljava/lang/String;)Z", false);
27 OpenURLFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_OpenURL", "(Ljava/lang/String;)V", false);
28 GetIntentDataFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_GetIntentData", "()Ljava/lang/String;", false);
29 GetApplicationExtraFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_GetApplicationExtra", "(Ljava/lang/String;)Ljava/lang/String;", false);
30 GetDeviceSerialNumberFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_GetDeviceSerialNumber", "()Ljava/lang/String;", false);
31 GetDeviceMacAddressFunction = FJavaWrapper::FindMethod(Env, FJavaWrapper::GameActivityClassID, "AndroidThunkJava_GetMacAddress", "()Ljava/lang/String;", false);
32 }
33#endif
34}
35
36bool UPixoLauncherSubsystem::IsApplicationInstalled(const FString& ApplicationName)
37{
38 bool bResult = false;
39#if PLATFORM_ANDROID
40 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
41 {
42 auto PackageNameArg = FJavaHelper::ToJavaString(Env, ApplicationName);
43 bResult = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, FJavaWrapper::AndroidThunkJava_IsPackageInstalled, *PackageNameArg);
44 }
45
46 Log("UPixoLauncherSubsystem::IsApplicationInstalledFunction: %d", bResult);
47#endif
48 return bResult;
49}
50
51bool UPixoLauncherSubsystem::LaunchApplication(const FString& ApplicationName, const TArray<FString>& ExtraKey, const TArray<FString>& ExtraValue)
52{
53 bool bResult = false;
54#if PLATFORM_ANDROID
55 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
56 {
57 auto ApplicationNameArg = FJavaHelper::ToJavaString(Env, ApplicationName);
58
59 // Convert scope array into java fields
60 auto ExtraKeyArg = NewScopedJavaObject(Env, (jobjectArray)Env->NewObjectArray(ExtraKey.Num(), FJavaWrapper::JavaStringClass, nullptr));
61 auto ExtraValueArg = NewScopedJavaObject(Env, (jobjectArray)Env->NewObjectArray(ExtraKey.Num(), FJavaWrapper::JavaStringClass, nullptr));
62 for (uint32 Param = 0; Param < ExtraKey.Num(); Param++)
63 {
64 auto KeyStringValue = FJavaHelper::ToJavaString(Env, ExtraKey[Param]);
65 Env->SetObjectArrayElement(*ExtraKeyArg, Param, *KeyStringValue);
66
67 auto ValueStringValue = FJavaHelper::ToJavaString(Env, ExtraValue[Param]);
68 Env->SetObjectArrayElement(*ExtraValueArg, Param, *ValueStringValue);
69 }
70 bResult = FJavaWrapper::CallBooleanMethod(Env, FJavaWrapper::GameActivityThis, LaunchApplicationFunction, *ApplicationNameArg, *ExtraKeyArg, *ExtraValueArg);
71 }
72
73 Log("UPixoLauncherSubsystem::LaunchApplication: %s, %i : %i", *ApplicationName, ExtraKey.Num(), ExtraValue.Num());
74#endif
75 return bResult;
76}
77
78void UPixoLauncherSubsystem::OpenURL(const FString& URL)
79{
80#if PLATFORM_ANDROID
81 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
82 {
83 auto URLArg = FJavaHelper::ToJavaString(Env, URL);
84 FJavaWrapper::CallVoidMethod(Env, FJavaWrapper::GameActivityThis, OpenURLFunction, *URLArg);
85 }
86
87 Log("UPixoLauncherSubsystem::OpenURL: %s", *URL);
88#endif
89}
90
91FString UPixoLauncherSubsystem::GetApplicationExtra(const FString& ExtraKey)
92{
93 FString ReturnedExtraValue = FString("");
94#if PLATFORM_ANDROID
95 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
96 {
97 auto ExtraKeyArg = FJavaHelper::ToJavaString(Env, ExtraKey);
98 auto JavaKeyValue = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, GetApplicationExtraFunction, *ExtraKeyArg);
99 ReturnedExtraValue = FJavaHelper::FStringFromLocalRef(Env, JavaKeyValue);
100 }
101
102 Log("UPixoLauncherSubsystem::GetApplicationExtra: %s", *ReturnedExtraValue);
103#endif
104 return ReturnedExtraValue;
105}
106
108{
109 FString ReturnedExtraValue = FString("");
110#if PLATFORM_ANDROID
111 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
112 {
113 auto JavaKeyValue = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, GetIntentDataFunction);
114 ReturnedExtraValue = FJavaHelper::FStringFromLocalRef(Env, JavaKeyValue);
115 }
116
117 Log("UPixoLauncherSubsystem::GetIntentData: %s", *ReturnedExtraValue);
118#endif
119 return ReturnedExtraValue;
120}
121
123{
124 FString ReturnedExtraValue = FString("");
125#if PLATFORM_ANDROID
126 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
127 {
128 auto JavaKeyValue = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, GetDeviceSerialNumberFunction);
129 ReturnedExtraValue = FJavaHelper::FStringFromLocalRef(Env, JavaKeyValue);
130 }
131
132 Log("UPixoLauncherSubsystem::GetDeviceSerialNumber: %s", *ReturnedExtraValue);
133#else
134 ReturnedExtraValue = TEXT("");
135#endif
136 return ReturnedExtraValue;
137}
138
140{
141 FString ReturnedExtraValue = FString("");
142#if PLATFORM_ANDROID
143 if (JNIEnv* Env = FAndroidApplication::GetJavaEnv())
144 {
145 auto JavaKeyValue = (jstring)FJavaWrapper::CallObjectMethod(Env, FJavaWrapper::GameActivityThis, GetDeviceMacAddressFunction);
146 ReturnedExtraValue = FJavaHelper::FStringFromLocalRef(Env, JavaKeyValue);
147 }
148
149 Log("UPixoLauncherSubsystem::GetDeviceMacAddress: %s", *ReturnedExtraValue);
150#else
151 ReturnedExtraValue = FGenericPlatformMisc::GetMacAddressString();
152#endif
153 return ReturnedExtraValue;
154}
155
156#undef Fatal
157#undef Error
158#undef Warn
159#undef Log
#define Log(pmt,...)
Definition ApexAPI.cpp:14
DEFINE_LOG_CATEGORY_STATIC(LogPixoLauncherSubsystem, Log, All)
FString GetDeviceSerialNumber()
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
bool LaunchApplication(const FString &ApplicationName, const TArray< FString > &ExtraKey, const TArray< FString > &ExtraValue)
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
FString GetApplicationExtra(const FString &ExtraKey)
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
FString GetDeviceMacAddress()
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
FString GetIntentData()
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
bool IsApplicationInstalled(const FString &ApplicationName)
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
void OpenURL(const FString &URL)
UFUNCTION(BlueprintCallable, Category = "PixoVR|Launcher")
void Initialize(FSubsystemCollectionBase &Collection)