Skip to content

Instantly share code, notes, and snippets.

@error454

error454/example.cpp

Last active Sep 26, 2019
Embed
What would you like to do?
Vivox UE4 Quest Microphone
#include "AndroidPermissionFunctionLibrary.h"
#include "AndroidPermissionCallbackProxy.h"
void SomeFuncWhereYouNeedPermissions()
{
#if PLATFORM_ANDROID
// If we don't have the permission
if (!UAndroidPermissionFunctionLibrary::CheckPermission(TEXT("android.permission.RECORD_AUDIO")))
{
// Build an array of permissions to request
TArray<FString> Perms;
Perms.Add(TEXT("android.permission.RECORD_AUDIO"));
if (UAndroidPermissionCallbackProxy* Callback = UAndroidPermissionFunctionLibrary::AcquirePermissions(Perms))
{
// Bind to the callback so we know when permissions have been granted
Callback->OnPermissionsGrantedDelegate.BindLambda([this](const TArray<FString>& Permissions, const TArray<bool>& GrantResults)
{
// If you requested more than 1 permission, then you should check the Permissions array to see if
// your specific permission got granted. In this case, we only requested a single permission.
if (GrantResults.Num() > 0)
{
if (GrantResults[0])
{
// We got RECORD_AUDIO permission, now we can use the mic
Login(GetFirstGamePlayer()->GetPreferredUniqueNetId()->ToString());
}
}
});
}
}
else
{
// We already had permissions so continue using the mic
UE_LOG(LogTemp, Warning, TEXT("Already had RECORD_AUDIO permissions"));
Login(GetFirstGamePlayer()->GetPreferredUniqueNetId()->ToString());
}
#else // Not Android
Login(GetFirstGamePlayer()->GetPreferredUniqueNetId()->ToString());
#endif
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.