javaandroidandroid-11

PROCESS_TEXT Not visible in text selection menu in most apps after Android 11


I have the following configuration in the manifest file -

<activity
            android:name=".activities.PopupWord"
            android:excludeFromRecents="true"
            android:theme="@style/popups">
            <intent-filter>
                <action android:name="android.intent.action.SEARCH" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/*" />
            </intent-filter>
            <intent-filter>
                <action android:name="android.intent.action.PROCESS_TEXT" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/*" />
            </intent-filter>

            <intent-filter>
                <action android:name="android.intent.action.SEND" />
                <category android:name="android.intent.category.DEFAULT" />
                <data android:mimeType="text/*" />
            </intent-filter>

        </activity>

I can see my 'Lookup' Button in the text selection menu in apps like twitter in Android 10 but in Android 11 it vanished. Surprisingly it works in Chrome.

Wikipedia Beta, somehow circumvents this issue and shows its 'Search in Wikipedia' Button everywhere. I tried to see it's manifest and found it to be similar.

<activity
            android:name="org.wikipedia.search.SearchActivity"
            android:windowSoftInputMode="0x10">

            <intent-filter
                android:label="@ref/0x7f100190">
                <action
                    android:name="android.intent.action.SEND" />
                <category
                    android:name="android.intent.category.DEFAULT" />
                <data
                    android:mimeType="text/plain" />
            </intent-filter>

            <intent-filter
                android:label="@ref/0x7f100190">
                <action
                    android:name="android.intent.action.PROCESS_TEXT" />
                <category
                    android:name="android.intent.category.DEFAULT" />
                <data
                    android:mimeType="text/plain" />
            </intent-filter>
        </activity>

(I have tried making mimeType text/plain and adding a label, it doesn't help)

Any leads will be helpful.


Solution

  • Edit - Solution - https://stackoverflow.com/a/72930519/6590844

    So I found the probable reason of this happening.

    1. Apps using custom text edit box or text box need to manually add the buttons in the text selection menu by running the following code (More Details)
        public void onInitializeMenu(Menu menu) {
        // Start with a menu Item order value that is high enough
        // so that your "PROCESS_TEXT" menu items appear after the
        // standard selection menu items like Cut, Copy, Paste.
        int menuItemOrder = 100;
        for (ResolveInfo resolveInfo : getSupportedActivities()) {
            menu.add(Menu.NONE, Menu.NONE,
                    menuItemOrder++,
                    getLabel(resolveInfo))
                    
    .setIntent(createProcessTextIntentForResolveInfo(resolveInfo))
                    .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        }
    }
    
    
    1. This requires apps to scan existing packages for Process_text intent support but in Android 11, we can't access all installed packages but only the ones inside <queries> </queries> in androidManifest.xml.

    2. Wikipedia being a famous app, twitter must have added it in the queries list, hence the support.