6

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.

Gaurav Sharma
  • 296
  • 2
  • 11

3 Answers3

3

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.

Gaurav Sharma
  • 296
  • 2
  • 11
3

Had the same issue: I wanted the Translate option after text selection and long could not find the reason why it's missing in my app targeting Android 11. It looks like even using standard views without custom menus we have to specify the PROCESS_TEXT intent in the <queries>

<queries>
    <intent>
        <action android:name="android.intent.action.PROCESS_TEXT" />
        <data android:mimeType="text/plain" />
    </intent>
</queries>

With this snippet all external apps items are visible as expected.

Derek K
  • 2,756
  • 1
  • 21
  • 37
  • 1
    For me, this is the correct answer. For more context, the visibility of apps to each other changed in android 11 (API 30). Some system apps are visible to everything but other apps are only visible under specific circumstances, see here: https://developer.android.com/training/package-visibility/automatic For more information on how the queries block works, see here: https://developer.android.com/guide/topics/manifest/queries-element – Simon Nov 23 '21 at 14:52
  • 3
    This is valid for the apps that want to show actions from other apps who advertise PROCESS_TEXT, the question is actually for the inverse, my app advertises the process_text action, but many app don't honour it. Read more here - https://developer.android.com/training/package-visibility/use-cases#custom-text-selection-actions – Gaurav Sharma Jan 26 '22 at 11:31
0

After decompiling Messages, Wikpedia, and Dictionary.com and inspecting the various manifests and comparing Messages behavior to other apps and system text boxes, the only conclusion is that Messages has a dynamic whitelist configured by Google at runtime. The package names are nowhere to be found in the code (that would not be unprecedented; you can find exceptions for facebook published package names in parts of AOSP to make sure they don't break).

The only part of the select text-> populate menu options process that remains unclear is exactly which system pre analyzes the text and determines whether to show the Maps/Places option if it thinks it's an address, such as when the beginning of the selection is a number. Regardless, it's certainly a process outside the control of the providing process text app.

sbaar
  • 1,429
  • 1
  • 17
  • 33