Android Question [Solved] - Querying the TalkBack status

rleiman

Well-Known Member
Licensed User
Longtime User
Greeting everyone,

I found some code in the forum that should be telling me if TalkBack is turned on by the user. The Log statement returns True with TalkBack turned off as well as on. The code is from 2012 so maybe it's too much outdated? If that's the case, is there any updated code that will return the TalkBack status?

Thanks.

TalkBack query from 2012:
Dim r As Reflector
r.Target = r.GetContext
r.Target = r.RunMethod2("getSystemService", "accessibility", "java.lang.String")
Dim accessibility = r.RunMethod("isEnabled"), _
    isExploreByTouchEnabled = r.RunMethod("isTouchExplorationEnabled") As Boolean
Log(accessibility)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
Untested code:
B4X:
Dim context As JavaObject
Dim AccessibilityManager As JavaObject = context.InitializeContext.RunMethod("getSystemService", Array("accessibility"))
If AccessibilityManager.IsInitialized Then
 Dim services As List = AccessibilityManager.RunMethod("getEnabledAccessibilityServiceList", Array(1)) 'FEEDBACK_SPOKEN
If services.Size > 0 Then
 Log("Talkback is active")
End If


Based on: https://stackoverflow.com/a/59950182/971547
 
Upvote 0

rleiman

Well-Known Member
Licensed User
Longtime User
Untested code:
B4X:
Dim context As JavaObject
Dim AccessibilityManager As JavaObject = context.InitializeContext.RunMethod("getSystemService", Array("accessibility"))
If AccessibilityManager.IsInitialized Then
Dim services As List = AccessibilityManager.RunMethod("getEnabledAccessibilityServiceList", Array(1)) 'FEEDBACK_SPOKEN
If services.Size > 0 Then
Log("Talkback is active")
End If


Based on: https://stackoverflow.com/a/59950182/971547
Thanks for the revised coding. I'm now using it as a sub routine.

B4X:
Sub TalkBackIsActive As Boolean
    
    Dim blnReturnValue As Boolean = False
    Dim context As JavaObject
    Dim AccessibilityManager As JavaObject = context.InitializeContext.RunMethod("getSystemService", _
        Array("accessibility"))

    If AccessibilityManager.IsInitialized Then
        Dim services As List = AccessibilityManager.RunMethod("getEnabledAccessibilityServiceList", _
            Array(1)) 'FEEDBACK_SPOKEN

        If services.Size > 0 Then
            blnReturnValue = True
        End If
    End If
    
    Return blnReturnValue
End Sub
 
Upvote 0
Top