Request light estimation permission
Request the Android system permission that light estimation requires before you enable the AR Camera Manager component.
AR Foundation's light estimation feature requires an Android system permission on the Android XR runtime. Your user must grant your app the android.permission.SCENE_UNDERSTANDING_COARSE permission before it can track scene data.
To request multiple permissions at once, refer to Request multiple permissions simultaneously.
Prerequisites
Before you request light estimation permission, enable the Android XR: Camera (Passthrough) feature. For instructions, refer to Configure project settings.
Request permission and enable the AR Camera Manager component
To avoid permission-related errors at runtime, enable the AR Camera Manager component only after the user grants the required permission.
To request the permission and enable the AR Camera Manager component:
- Set up your scene with the AR Camera Manager component disabled.
- Request the
android.permission.SCENE_UNDERSTANDING_COARSEpermission. - After the user grants the permission, enable the AR Camera Manager component.
The following example code demonstrates how to request the required permission and enable the AR Camera Manager component:
const string k_Permission =
"android.permission.SCENE_UNDERSTANDING_COARSE";
[SerializeField]
ARCameraManager m_ARCameraManager;
#if UNITY_ANDROID
void Start()
{
if (!Permission.HasUserAuthorizedPermission(k_Permission))
{
var callbacks = new PermissionCallbacks();
callbacks.PermissionDenied += OnPermissionDenied;
callbacks.PermissionGranted += OnPermissionGranted;
Permission.RequestUserPermission(k_Permission, callbacks);
}
else
{
// Enable the AR Camera Manager component if permission is
// already granted.
m_ARCameraManager.enabled = true;
}
}
void OnPermissionDenied(string permission)
{
// Handle denied permission.
}
void OnPermissionGranted(string permission)
{
// Enable the AR Camera Manager component after the user grants
// permission.
m_ARCameraManager.enabled = true;
m_ARCameraManager.subsystem.Stop();
m_ARCameraManager.subsystem.Start();
}
#endif // UNITY_ANDROID
After the user grants the permission and your app enables the AR Camera Manager component, your app can use light estimation without permission-related errors.
Additional resources
- Permissions
- Camera feature support reference
- AR Camera Manager component (AR Foundation)