How can we add a new context menu option to all the apps that would show up when user selects a text and long presses on it?
Let's say I want to provide user the capability of finding the meaning of a word from an offline dictionary without having to navigate away from his app context.
I'm quite new to android development. So any detailed answers or pointers to samples will be of great help. I'm assuming this should be possible to do as the apps "define", "define offline dictionary" seem to do something close to this if not exactly same. In these apps, you can select text and click on copy to see the meaning of the text.
All the search that I have done have shown me examples on how to render a context menu for a text view or how to get selected list item in the context menu handler. But that is not helpful.
Thanks in advance.
A context menu is a pop-up menu that provides shortcuts for actions the software developer anticipates the user might want to take. In a Windows environment, the context menu is accessed with a right mouse click.
Creating a custom right-click menu in React. To create a right-click menu, we need to use the contextmenu event listener. This event fires when the user attempts to open a context menu. It is typically triggered by clicking the right mouse button, or by pressing the context menu keyboard shortcut.
The contextmenu global attribute is the id of a <menu> to use as the contextual menu for this element. A context menu is a menu that appears upon user interaction, such as a right-click. HTML now allows us to customize this menu. Here are some implementation examples, including nested menus.
I think this can help you, says how to create the Context menu and get the selected text. with that you just need to do a intent to a dictionary giving that selected text as a extra:
https://nitesh.morajkar.com/how-to-select-and-share-text-with-intents-in-android/
And if you want to use for example the google translator for definitions this can help:
Android API support dictionary applications
EDIT: after some search by both the solution for this question is here: https://medium.com/google-developers/custom-text-selection-actions-with-action-process-text-191f792d2999#.h6377bc8j
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With