joecks joecks - 1 year ago 157
Android Question

Android Marshmallow Text Selection Option Menu Actions

Hi I would like to add a global text selection listener which shows a sub menu for a any selected text. Android 6 allows this with the new Text Selection listener.

enter image description here

Is it possible to use this functionality by an external app, which then populates the sub menu?

Answer Source

The concept is called ACTION_PROCESS_TEXT and is available in Android 6:

Define an intent filter in your Manifest:

<activity android:name=".YourActivity" 
        <action android:name="android.intent.action.PROCESS_TEXT" />
        <category android:name="android.intent.category.DEFAULT" />
        <data android:mimeType="text/plain" />

Then handle the intent in your activity:

protected void onCreate(Bundle savedInstanceState) {
  CharSequence text = getIntent()
  // process the text
  boolean readonly = getIntent()
  .getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false);

You can only define one Action per Activity.



Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download