- Home /
Can the accessibility “Magnification Gesture” be detected on Android?
My game sometimes requires repeated tapping. Some players are complaining that it doesn't work when they have the "triple tap to zoom" accessibility gesture system setting enabled on their device.
Web search showed me that it can't be disabled during gameplay, but can it be detected? At least then I can explain to users how to turn it off while playing.
I'm not sure which android API I could use to check this setting. I'm not a native android developer and Google isn't turning up much. Help is much appreciated!
Answer by tessellation · Dec 30, 2017 at 08:48 AM
I figured this out. Here's the code to do it in Java:
Settings.Secure.getInt( context.getContentResolver(), "accessibility_display_magnification_enabled" );
...just check the return value: 1 = enabled, 0 = disabled
Here's the code to do it in a Unity C# Script:
public static bool CheckForSystemZoomEnabled()
{
#if UNITY_ANDROID
try {
using(AndroidJavaClass clsUnity = new AndroidJavaClass("com.unity3d.player.UnityPlayer"))
{
AndroidJavaObject objActivity = clsUnity.GetStatic<AndroidJavaObject>("currentActivity");
AndroidJavaObject objResolver = objActivity.Call<AndroidJavaObject>("getContentResolver");
using(AndroidJavaClass clsSecure = new AndroidJavaClass("android.provider.Settings$Secure"))
{
int val = clsSecure.CallStatic<int>("getInt", objResolver, "accessibility_display_magnification_enabled");
return val != 0;
}
}
} catch(System.Exception) { }
#endif
return false;
}
@tessellation thanks SO much for this code!
Quick question: Do you know if this code can be called on older devices that don't support $$anonymous$$agnification? I currently allow very old OS and devices to run on my game and don't want to break them. Any help would be appreciated!
Thanks!
@breban1 I don't see why not, if any Java class doesn't exist, it should throw an exception and the catch will hit and return false. But you should always test yourself if possible.
It looks like it is working on my test devices, thanks again for posting your own answer!
Your answer
Follow this Question
Related Questions
Normal map is not working with Unity 5 when Low-level Native Plugin Interface is used 0 Answers
How to enable transparency on Android to allow Unity to be used as overlay in native application 2 Answers
native android plugin 0 Answers
Different approaches to Android plugins 0 Answers
Android - Trying to Load Library bug 0 Answers