From 2efcdf57871cc7a8def6a83995cf6f0d7f66f925 Mon Sep 17 00:00:00 2001 From: Igor Randjelovic Date: Mon, 21 Feb 2022 18:34:32 +0100 Subject: [PATCH] fix(android): api17 crash on a11y service (#9792) --- .../accessibility-service.android.ts | 25 ++++++++++--------- 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/packages/core/accessibility/accessibility-service.android.ts b/packages/core/accessibility/accessibility-service.android.ts index 91ce754ae..898838670 100644 --- a/packages/core/accessibility/accessibility-service.android.ts +++ b/packages/core/accessibility/accessibility-service.android.ts @@ -71,19 +71,20 @@ function ensureStateListener(): SharedA11YObservable { } }, }); - - touchExplorationStateChangeListener = new android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener({ - onTouchExplorationStateChanged(enabled) { - updateAccessibilityState(); - - if (Trace.isEnabled()) { - Trace.write(`TouchExplorationStateChangeListener state changed to: ${!!enabled}`, Trace.categories.Accessibility); - } - }, - }); - accessibilityManager.addAccessibilityStateChangeListener(accessibilityStateChangeListener); - accessibilityManager.addTouchExplorationStateChangeListener(touchExplorationStateChangeListener); + + if (android.os.Build.VERSION.SDK_INT >= 19) { + touchExplorationStateChangeListener = new android.view.accessibility.AccessibilityManager.TouchExplorationStateChangeListener({ + onTouchExplorationStateChanged(enabled) { + updateAccessibilityState(); + + if (Trace.isEnabled()) { + Trace.write(`TouchExplorationStateChangeListener state changed to: ${!!enabled}`, Trace.categories.Accessibility); + } + }, + }); + accessibilityManager.addTouchExplorationStateChangeListener(touchExplorationStateChangeListener); + } updateAccessibilityState();