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:44 +01:00
parent 360801b574
commit 0be660e411
3 changed files with 33 additions and 10 deletions
@@ -35,6 +35,7 @@
#include "SenseGloveAndroidModule.h" #include "SenseGloveAndroidModule.h"
#include "SGAndroid/SGAndroidPermissions.h"
#include "SGAndroid/SGConnectJNI.h" #include "SGAndroid/SGConnectJNI.h"
#include "SGAndroid/SGCoreJNI.h" #include "SGAndroid/SGCoreJNI.h"
#include "SGLog/SGLog.h" #include "SGLog/SGLog.h"
@@ -45,16 +46,8 @@ void FSenseGloveAndroidModule::StartupModule()
{ {
SGLOG("Starting up the SenseGloveAndroid module..."); SGLOG("Starting up the SenseGloveAndroid module...");
#if PLATFORM_ANDROID OnPostEngineInitHandle = FCoreDelegates::OnPostEngineInit.AddRaw(
const int32 R1 = FSGConnectJNI::Initialize(); this, &FSenseGloveAndroidModule::OnPostEngineInit);
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 */
} }
void FSenseGloveAndroidModule::PreUnloadCallback() void FSenseGloveAndroidModule::PreUnloadCallback()
@@ -72,4 +65,26 @@ void FSenseGloveAndroidModule::ShutdownModule()
SGLOG("Shutting down the SenseGloveAndroid module..."); 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 #undef LOCTEXT_NAMESPACE
@@ -35,17 +35,24 @@
#pragma once #pragma once
#include "Delegates/IDelegateInstance.h"
#include "Modules/ModuleInterface.h" #include "Modules/ModuleInterface.h"
#define LOCTEXT_NAMESPACE "SenseGloveAndroid" #define LOCTEXT_NAMESPACE "SenseGloveAndroid"
class FSenseGloveAndroidModule : public IModuleInterface class FSenseGloveAndroidModule : public IModuleInterface
{ {
private:
FDelegateHandle OnPostEngineInitHandle;
public: public:
virtual void StartupModule() override; virtual void StartupModule() override;
virtual void PreUnloadCallback() override; virtual void PreUnloadCallback() override;
virtual void PostLoadCallback() override; virtual void PostLoadCallback() override;
virtual void ShutdownModule() override; virtual void ShutdownModule() override;
private:
void OnPostEngineInit() const;
}; };
#undef LOCTEXT_NAMESPACE #undef LOCTEXT_NAMESPACE
@@ -46,6 +46,7 @@ public class SenseGloveAndroid : ModuleRules
PrivateDependencyModuleNames.AddRange( PrivateDependencyModuleNames.AddRange(
new string[] new string[]
{ {
"AndroidPermission",
"Core", "Core",
"CoreUObject", "CoreUObject",
"Engine", "Engine",