getScreenText static method

Future<String> getScreenText()

Retrieves all text currently visible on the screen. Requires the Accessibility Service to be enabled. Returns the screen text as a single String.

Implementation

static Future<String> getScreenText() async {
  try {
    final result = await _channel.invokeMethod<String>('getScreenText');
    return result ?? '';
  } on PlatformException catch (e) {
    if (e.code == 'PERMISSION_DENIED') {
      throw Exception(
          'Accessibility permission is not enabled. Please grant permission first.');
    } else {
      throw Exception('Failed to get screen text: ${e.message}');
    }
  }
}