Adding Your Add-On to Context Menus

Users who have installed your add-on can access it through the overflow menu in Google Apps. However, some actions pertain to a particular context in the app; these actions are easier to access when they appear in the context menu for that context.

For example, an action in your Sheets add-on might be appropriate when columns are selected in the Sheets editor. Adding this action to the Sheets column selection context menu will make it quick and easy to access.

This page describes how you can add context menu items for your add-on.

You use meta-data elements in your Android manifest to specify the contexts in which your add-on should appear:

<meta-data android:name=context android:value=activity />

This name-value pair associates one of the defined context names with an activity in your Android add-on.

If you associate a context with an activity, that activity will (by default) no longer appear in the editor's main menu under Add-ons. It will only appear in the associated context menu. If you need the activity to appear in both the context menu and the main menu, define an <activity-alias> in your manifest and associate either the activity or the alias with the context. You should only do this, however, if the activity presents a good experience with and without a linked context.

Available contexts

The following tables show the contexts that you can use to associate actions from your add-on.

Docs

Docs contexts are specified as com.google.android.apps.docs.editors.docs.context-name, where context-name is one of the following:

Context name Description
IMAGE_SELECTION The context of a selected image
TEXT_SELECTION The context of a range of selected text

Sheets

Sheets contexts are specified as com.google.android.apps.docs.editors.sheets.context-name, where context-name is one of the following:

Context name Description
COLUMN_SELECTION The context of one or more selected columns
ROW_SELECTION The context of one or more selected rows
RANGE_SELECTION The context of a selected range

Example Manifest

The following sample manifest shows how to add add-on activities to context menus. In this case, the add-on has two activities and associates each of them with different contexts. The MainActivity also has an alias defined so that it can be accessed through the Docs and Sheets main menu. MainActivity is also the Launcher Activity, and will be used as the entry point if the add-on is launched directly.

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.example.demo.addon"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.USE_CREDENTIALS" />
    <uses-sdk
        android:minSdkVersion="17"
        android:targetSdkVersion="22" />

    <application
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/DemoTheme" >

        <meta-data
            android:name="com.google.android.apps.docs.editors.sheets.RANGE_SELECTION"
            android:value="com.example.demo.addon.TextActivity" />
        <meta-data
            android:name="com.google.android.apps.docs.editors.sheets.ROW_SELECTION"
            android:value="com.example.demo.addon.MainActivity" />
        <meta-data
            android:name="com.google.android.apps.docs.editors.sheets.COLUMN_SELECTION"
            android:value="com.example.demo.addon.MainActivity" />

        <meta-data
            android:name="com.google.android.apps.docs.editors.docs.TEXT_SELECTION"
            android:value="com.example.demo.addon.TextActivity" />
        <meta-data
            android:name="com.google.android.apps.docs.editors.docs.IMAGE_SELECTION"
            android:value="com.example.demo.addon.MainActivity" />

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter
                android:icon="@mipmap/ic_launcher" >
                <!-- This intent filter is what allows the app to be called
                     as an add-on from the Sheets and Docs editors. -->
                <action android:name="com.google.android.apps.docs.editors.sheets.ADDON" />
                <action android:name="com.google.android.apps.docs.editors.docs.ADDON" />
            </intent-filter>

            <intent-filter>
                <!-- This intent filter sets MainActivity as the entry
                     point when the add-on is launched directly. -->
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name=".TextActivity"
            android:label="@string/text_activity_label" >
            <intent-filter
                android:icon="@mipmap/ic_launcher2" >
                <action android:name="com.google.android.apps.docs.editors.sheets.ADDON" />
                <action android:name="com.google.android.apps.docs.editors.docs.ADDON" />
            </intent-filter>
        </activity>

        <!-- This alias allows the MainActivity to appear in the main Add-on
             menus in the Docs and Sheets editors as well as the context
             menu. -->
        <activity-alias
          android:name=".MainActivityAlias"
          android:targetActivity=".MainActivity"
          android:label="@string/app_name"
          android:exported="true" >
          <intent-filter
              android:icon="@mipmap/ic_launcher" >
              <action android:name="com.google.android.apps.docs.editors.sheets.ADDON" />
              <action android:name="com.google.android.apps.docs.editors.docs.ADDON" />
          </intent-filter>
        </activity-alias>

    </application>

</manifest>

Send feedback about...

Apps Script
Apps Script