Skip to content

Instantly share code, notes, and snippets.

@streepje8
Last active April 16, 2026 11:27
Show Gist options
  • Select an option

  • Save streepje8/9af0276d892972372b3eb61ca02c31f5 to your computer and use it in GitHub Desktop.

Select an option

Save streepje8/9af0276d892972372b3eb61ca02c31f5 to your computer and use it in GitHub Desktop.
Disable Proximity Sensor Unity Meta Quest
using System;
#if UNITY_ANDROID && !UNITY_EDITOR
using UnityEngine;
#endif
namespace WezzelNL.WZVR.Runtime.Util
{
public static class AndroidUtil
{
public static void SendBroadcastIntent(string action)
{
#if UNITY_ANDROID && !UNITY_EDITOR
try
{
using var intent = new AndroidJavaObject("android.content.Intent", action);
using var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
using var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity");
activity.Call("sendBroadcast", intent);
Debug.Log($"Broadcast sent: {action}");
}
catch (Exception e)
{
Debug.LogError($"Failed to send broadcast intent: {e.Message}");
}
#else
throw new PlatformNotSupportedException("Sending broadcast intents is only supported on Android.");
#endif
}
}
}
namespace WezzelNL.WZVR.Runtime.Util
{
public static class MetaQuestProximitySensor
{
private const string ProxDisable = "com.oculus.vrpowermanager.prox_close";
private const string ProxEnable = "com.oculus.vrpowermanager.automation_disable";
public static void Enable() => AndroidUtil.SendBroadcastIntent(ProxEnable);
public static void Disable() => AndroidUtil.SendBroadcastIntent(ProxDisable);
}
}
using UnityEngine;
namespace WezzelNL.WZVR.Runtime.Util
{
public class ProximitySensorManager : MonoBehaviour
{
#if UNITY_ANDROID && !UNITY_EDITOR
private void OnEnable() => MetaQuestProximitySensor.Disable();
private void OnDisable() => MetaQuestProximitySensor.Enable();
#endif
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment