0

Is it possible to add more options to Android default Contextual Action Bar, what I mean is not only changing it in one application, but also altering all CABs in the entire system. If it's not possible, is there any other way to write an app which reacts when I select a text in different applications (ex. browser, Gmail etc.) and make it for example pop up on the side.

I don't expect any code, just a general approach and some hints how to achieve a similar behavior.

radzak
  • 2,986
  • 1
  • 18
  • 27

1 Answers1

0

Is it possible to add more options to Android default Contextual Action Bar, what I mean is not only changing it in one application, but also altering all CABs in the entire system.

There is no "default Contextual Action Bar" in general. Certain widgets may have a default contextual action bar (a.k.a., action mode).

Given some of the rest of your question, I am guessing that by "default Contextual Action Bar", you mean for the EditText widget (or anything else based on TextView that allows text selection).

In that case, on Android 6.0 and higher, you can implement an ACTION_PROCESS_TEXT activity, which will be integrated as an option into the text selection floating action mode. Note that this action mode is only available in portrait mode, so your activity will not appear as an option in landscape.

There is no similar option for Android 5.1 and earlier.

is there any other way to write an app which reacts when I select a text in different applications

You might be able to accomplish this by writing an AccessibilityService. Note that the user has to opt into enabling your AccessibilityService in the Settings app, which will warn the user about the privacy implications involved in allowing your app to spy on all their input.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thank you so much for your answer! Does user have to opt into enabling `ACTION_PROCESS_TEXT` activity? Which of these two approaches would you use, in terms of compatibility and user privacy? I guess `ACTION_PROCESS_TEXT` doesn't spy on all input. Sorry, but I'm really new to all this stuff, but I'd like to know what of these mechanisms are better to use in my case, when the visual aspect is no object. – radzak May 30 '16 at 16:24
  • @Jatimir: "Does user have to opt into enabling ACTION_PROCESS_TEXT activity?" -- no, unless Android changed that behavior and I missed it. "Which of these two approaches would you use, in terms of compatibility and user privacy?" -- `ACTION_PROCESS_TEXT`. "I guess ACTION_PROCESS_TEXT doesn't spy on all input" -- correct. The user has to specifically tap your entry in the floating action mode, and so they "opt in" at that point, more or less. – CommonsWare May 30 '16 at 16:29