Skip to content

Instantly share code, notes, and snippets.

@error454
Last active May 25, 2021 00:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save error454/7403e51e89fafaa29cfad716b5b6d815 to your computer and use it in GitHub Desktop.
Save error454/7403e51e89fafaa29cfad716b5b6d815 to your computer and use it in GitHub Desktop.
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
Copy link

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
Copy link
Author

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