Hi Magic Leap Developers,
Some developers have asked how to access the System Hand Input / Hand Gesture preferences that the user has set on the device inside System Settings (Settings > Input > Gestures). I thought this was an interesting concept. Access to these settings could be useful for apps that support both controller and hand input, so they can automatically enable/disable hand tracking based on the user’s preference. It could also allow the app to customize a specific gesture if it conflicts with the OS functionality. For instance, you may want to avoid using the close fist gesture if it triggers the Home menu.
Similar to other Android settings, the hand tracking settings can be accessed via the java Android.provider.Settings
class. To demonstrate how to do this, I have created a simple example that checks if the user has enabled the Home Hand Gesture or Hand Gesture Navigation options.
The code snippet below is written in Unity C#, but you can also use it as a reference for Native development.
//Returns true if the user is able to open the home menu with their gesture
public bool CheckHomeGestureMode()
{
// Get context
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var context = actClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass systemGlobal = new AndroidJavaClass("android.provider.Settings$System");
var homeGestureMode = systemGlobal.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "enable_home_gesture_inputs");
Debug.LogWarning("enable_home_gesture_inputs is set to : " + homeGestureMode);
return homeGestureMode > 0;
}
}
//Returns true if the user is able to navigate the home menu with their hands using the pinch gesture
public bool CheckPinchInputMode()
{
// Get context
using (var actClass = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
var context = actClass.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaClass systemGlobal = new AndroidJavaClass("android.provider.Settings$System");
var pinchGestureMode = systemGlobal.CallStatic<int>("getInt", context.Call<AndroidJavaObject>("getContentResolver"), "enable_pinch_gesture_inputs");
Debug.Log("enable_pinch_gesture_inputs is set to : " + pinchGestureMode);
return pinchGestureMode > 0;
}
}