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.

Is it possible to use this functionality by an external app, which then populates the sub menu?
The concept is called ACTION_PROCESS_TEXT and is available in Android 6:
Define an intent filter in your Manifest:
<activity android:name=".YourActivity" 
          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 handle the intent in your 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
  boolean readonly = getIntent()
  .getBooleanExtra(Intent.EXTRA_PROCESS_TEXT_READONLY, false);
}
You can only define one Action per Activity.
Source
Example
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