11

please look this screenshot. In normal case, when text be selected, a popup menu opened, but only have cut/paste item. I want to know, how to add item just like this "web search / share" into this popup menu?

What's this popup menu? I had tried to override Activity Context or Option Menu, but it' not. I had also tried to extends TextView and override it's Context menu, but no use, only show a normal dialog context menu, and this cut/paste menu disappered.

enter image description here

hyyou2010
  • 791
  • 11
  • 22

2 Answers2

14

Before the api23,I have no ideal too. But now we can get it use ACTION_PROCESS_TEXT with api23. Include this code in the AndroidManifest.xml file.

 <activity
        android:name=".YourActivity">
        <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>

Install your app, then you can find your app name in the text selection menu.

Sample

Read the documentation for more information.

Kamran Ahmed
  • 7,661
  • 4
  • 30
  • 55
jinsihou
  • 161
  • 1
  • 9
  • Great! Hope someone can tell us how to customize the popped menu, and use this in TextView, not only EditText. – hyyou2010 May 16 '17 at 09:17
  • I have in Google that whenever I select any text like "https://www.youtube.com/..." It shows YouTube app icon along with options like copy paste. How does it do it? – Astha Garg Oct 12 '20 at 14:59
  • 1
    any posibility for paste menu ? – SRB Bans Sep 10 '21 at 12:14
  • It works fine, but not in all Applications. In Google keep it doesn't work, as well as in Gmail, WhatsApp and Instagram. But for example, in Google Chrome it works fine – Hasan Mhd Amin Jul 06 '22 at 13:21
  • @HasanMhdAmin You need [another](https://stackoverflow.com/a/74417217/15055605) `intent-filter` too. – YaMiN Nov 12 '22 at 23:04
0

I tried @jinsihou's answer but as people said it's not working in all apps. After decompiling some apps and checking their AndroidManifest.xml I found that you should also add another intent-filter too.

<intent-filter>
    <action android:name="android.intent.action.VIEW" />
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE"/>
    <data android:scheme="https" android:host="google.com" android:pathPrefix="/test"/>
</intent-filter>

I'm not sure what's the significance of host or pathPrefix so I just entered dummy data.

YaMiN
  • 3,194
  • 2
  • 12
  • 36