Last active
April 16, 2026 11:27
-
-
Save streepje8/9af0276d892972372b3eb61ca02c31f5 to your computer and use it in GitHub Desktop.
Disable Proximity Sensor Unity Meta Quest
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | |
| } | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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