Send non-view availability event

We are going to send an accessibility event (which will be selected by TalkBack, etc.) that is not associated with the view.

For example, how can I send an availability event (for example, a talkback saying "Loaded data") when AsyncTask is finished?

+4
source share
3 answers

It appears that the current version of TalkBack is ignoring ads if AccessibilityEvent.getSource () returns null, so Toast is better. This has the added benefit of providing continuous feedback to users, regardless of whether they use TalkBack.

Toast.makeText(context, /** some text */, Toast.LENGTH_SHORT).show(); 

Typically, you can manually create an AccessibilityEvent and send it through the AccessibilityManager.

 AccessibilityManager manager = (AccessibilityManager) context .getSystemService(Context.ACCESSIBILITY_SERVICE); if (manager.isEnabled()) { AccessibilityEvent e = AccessibilityEvent.obtain(); e.setEventType(AccessibilityEvent.TYPE_ANNOUNCEMENT); e.setClassName(getClass().getName()); e.setPackageName(context.getPackageName()); e.getText().add("some text"); manager.sendAccessibilityEvent(e); } 
+5
source

You can use the availability manager directly (since API 14), e.g. @alanv. But since API 16, you must provide a view.

 final View parentView = view.getParent(); if (parentView != null) { final AccessibilityManager a11yManager = (AccessibilityManager) view.getContext().getSystemService(Context.ACCESSIBILITY_SERVICE); if (a11yManager != null && a11yManager.isEnabled()) { final AccessibilityEvent e = AccessibilityEvent.obtain(); view.onInitializeAccessibilityEvent(e); e.getText().add("some text"); parentView.requestSendAccessibilityEvent(view, e); } } 
+1
source

Try using a broadcast message, you can send an Intent to the Broadcast Receiver, and then in the Receiver you can trigger a notification or something else.

-1
source

Source: https://habr.com/ru/post/972400/


All Articles