How to add item into popup copy/paste menu on a android selected textview?
Asked Answered
B

3

12

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

Buskirk answered 23/12, 2015 at 16:22 Comment(0)
B
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.

Belcher answered 11/12, 2016 at 4:37 Comment(5)
Great! Hope someone can tell us how to customize the popped menu, and use this in TextView, not only EditText.Buskirk
I have in Google that whenever I select any text like "youtube.com..." It shows YouTube app icon along with options like copy paste. How does it do it?Craniology
any posibility for paste menu ?Sarina
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 fineCannonball
@HasanMhdAmin You need another intent-filter too.Auteur
A
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.

Auteur answered 12/11, 2022 at 23:3 Comment(0)
H
0

You should write your own context menu. There is a good example of how to do it in Google Chromium Android sources.

Find the class called FloatingPastePopupMenu.java here and see how it is used.

Hypabyssal answered 2/11, 2023 at 10:29 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.