revamp the way the plugin requests permisions on Android by showing a pop-up to the user rather than silently crashing if those permisions were not already given

This commit is contained in:
Mamadou Babaei
2024-11-14 00:26:03 +01:00
parent 3e1bae1e9a
commit afdaaf4950
3 changed files with 33 additions and 10 deletions
@@ -35,6 +35,7 @@
#include "SenseGloveAndroidModule.h"
#include "SGAndroid/SGAndroidPermissions.h"
#include "SGAndroid/SGConnectJNI.h"
#include "SGAndroid/SGCoreJNI.h"
#include "SGLog/SGLog.h"
@@ -45,16 +46,8 @@ void FSenseGloveAndroidModule::StartupModule()
{
SGLOG("Starting up the SenseGloveAndroid module...");
#if PLATFORM_ANDROID
const int32 R1 = FSGConnectJNI::Initialize();
const int32 R2 = FSGCoreJNI::Initialize();
ensureAlwaysMsgf(R1 == 0,
TEXT("Failed to initialize the SGConnect JNI bridge to SGConnect for Android! Status Code: %d"), R1);
ensureAlwaysMsgf(R2 == 0,
TEXT("Failed to initialize the SGCore JNI bridge to SGConnect for Android! Status Code: %d"), R2);
#endif /* PLATFORM_ANDROID */
OnPostEngineInitHandle = FCoreDelegates::OnPostEngineInit.AddRaw(
this, &FSenseGloveAndroidModule::OnPostEngineInit);
}
void FSenseGloveAndroidModule::PreUnloadCallback()
@@ -72,4 +65,26 @@ void FSenseGloveAndroidModule::ShutdownModule()
SGLOG("Shutting down the SenseGloveAndroid module...");
}
void FSenseGloveAndroidModule::OnPostEngineInit() const
{
#if PLATFORM_ANDROID
USGAndroidPermissions::GetInstance()->Request(
[](const TArray<FString>& Permissions, const TArray<bool>& GrantResults)
{
const int32 R1 = FSGConnectJNI::Initialize();
const int32 R2 = FSGCoreJNI::Initialize();
ensureAlwaysMsgf(R1 == 0,
TEXT(
"Failed to initialize the SGConnect JNI bridge to SGConnect for Android! Status Code: %d"
), R1);
ensureAlwaysMsgf(R2 == 0,
TEXT("Failed to initialize the SGCore JNI bridge to SGConnect for Android! Status Code: %d"
), R2);
});
#endif /* PLATFORM_ANDROID */
}
#undef LOCTEXT_NAMESPACE