Search Unity

Detecting TalkBack on a device

Discussion in 'Android' started by gfxguru, Jul 16, 2015.

  1. gfxguru

    gfxguru

    Joined:
    Jun 5, 2010
    Posts:
    107
    hi,
    For an app i need to check whether TalkBack is active or not on the device and issue a message. How can this be done without plugins and just using Android Helper classes in unity.

    From a stack overflow thread i got the native code for this :
    Code (JavaScript):
    1. AccessibilityManager am = (AccessibilityManager) getSystemService(ACCESSIBILITY_SERVICE);
    2. boolean isAccessibilityEnabled = am.isEnabled();
    3. boolean isExploreByTouchEnabled = am.isTouchExplorationEnabled();
    How can we access this using android helper functions..

    thanks in advance...
     
  2. gfxguru

    gfxguru

    Joined:
    Jun 5, 2010
    Posts:
    107
    hi,
    I was able to figure it out myself. Here is the code:
    Code (CSharp):
    1. using (var unityPlayer = new AndroidJavaClass("com.unity3d.player.UnityPlayer")) {
    2.             using (var activity = unityPlayer.GetStatic<AndroidJavaObject>("currentActivity")) {
    3.                 using (var context = activity.Call<AndroidJavaObject>("getApplicationContext")) {
    4.                     using (AndroidJavaObject accManager = context.Call<AndroidJavaObject>("getSystemService",new object[]{context.GetStatic<string>("ACCESSIBILITY_SERVICE")})) {
    5.                    
    6.                         return accManager.Call<bool>("isEnabled");
    7.                     }
    8.                 }
    9.             }
    10.         }
     
    Mest likes this.