How to add an item to the text selection popup menu?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP



How to add an item to the text selection popup menu?



When the user marks some text (inside of an EditText, WebView...) a floating text selection popup appears, where apps can add custom items. Can someone please give me an example, how to add an item to this popup menu which makes an intent and transfers the selected String to my activity.


EditText


WebView


String



enter image description here




1 Answer
1



This blog tutorial will show you how: https://medium.com/google-developers/custom-text-selection-actions-with-action-process-text-191f792d2999



Basically, in your Manifest file, add PROCESS_TEXT intent filter to the activity that will handle the text shared from popup menu.


Manifest


PROCESS_TEXT intent filter


<activity
android:name=".ProcessTextActivity"
android:label="@string/process_text_action_name">
<intent-filter>
<action android:name="android.intent.action.PROCESS_TEXT" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
</activity>



Then, you would process that text in your Activity like this


Activity


@Override
protected void onCreate(Bundle savedInstanceState)
super.onCreate(savedInstanceState);
setContentView(R.layout.process_text_main);
CharSequence text = getIntent()
.getCharSequenceExtra(Intent.EXTRA_PROCESS_TEXT);
// process the text






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

Firebase Auth - with Email and Password - Check user already registered

Dynamically update html content plain JS

How to determine optimal route across keyboard