Skip to content

Instantly share code, notes, and snippets.

@error454

error454/example.cpp

Last active May 25, 2021
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
}
@sthilton

This comment has been minimized.

Copy link

@sthilton sthilton commented May 24, 2021

Hi, this looks great. Have been having problems trying to integrate Vivox and no microphone access on the Quest. Where should this code be located?

@error454

This comment has been minimized.

Copy link
Owner Author

@error454 error454 commented May 25, 2021

It should be located prior to any code that tries to use the microphone.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment