2 Intent Filters, 1 Activity - Which opened it?

Never mind, found it. Just wasn't looking hard enough Using this.getIntent().getAction() in your Activity will spit out exactly what I was looking for, a String to identify which Intent Filter Action opened it.

Never mind, found it. Just wasn't looking hard enough... Using this.getIntent().getAction() in your Activity will spit out exactly what I was looking for, a String to identify which Intent Filter Action opened it.

You can see how this is done in the contacts application here: google. Com/codesearch/p? Hl=en#J8HqCFe1rOo/src/com/android/… – Jim Schubert Aug 1 '10 at 0:39.

This section looks at the intent filters declared in its manifest file. (If you're working offline in the SDK, you can find all the source files for this sample application, including its manifest file, at /samples/NotePad/index.html. In its manifest file, the Note Pad application declares three activities, each with at least one intent filter.

It also declares a content provider that manages the note data. The first activity, NotesList, is distinguished from the other activities by the fact that it operates on a directory of notes (the note list) rather than on a single note. It would generally serve as the initial user interface into the application.

This filter declares the main entry point into the Note Pad application. The standard MAIN action is an entry point that does not require any other information in the Intent (no data specification, for example), and the LAUNCHER category says that this entry point should be listed in the application launcher. This filter declares the things that the activity can do on a directory of notes.

It can allow the user to view or edit the directory (via the VIEW and EDIT actions), or to pick a particular note from the directory (via the PICK action). The mimeType attribute of the element specifies the kind of data that these actions operate on. It indicates that the activity can get a Cursor over zero or more items (vnd.android.cursor.

Dir) from a content provider that holds Note Pad data (vnd.google. The Intent object that launches the activity would include a content: URI specifying the exact data of this type that the activity should open. Note also the DEFAULT category supplied in this filter.

It's there because the Context.startActivity() and Activity. Therefore, the DEFAULT category is required for all filters — except for those with the MAIN action and LAUNCHER category. This filter describes the activity's ability to return a note selected by the user without requiring any specification of the directory the user should choose from.

The GET_CONTENT action is similar to the PICK action. In both cases, the activity returns the URI for a note selected by the user. (In each case, it's returned to the activity that called startActivityForResult() to start the NoteList activity.) Here, however, the caller specifies the type of data desired instead of the directory of data the user will be picking from.

The data type, vnd.android.cursor. Note, indicates the type of data the activity can return — a URI for a single note. From the returned URI, the caller can get a Cursor for exactly one item (vnd.android.cursor.

Item) from the content provider that holds Note Pad data (vnd.google. In other words, for the PICK action in the previous filter, the data type indicates the type of data the activity could display to the user. For the GET_CONTENT filter, it indicates the type of data the activity can return to the caller.

Launches the activity with no data specified. Launches the activity with no data selected specified. This is the actual intent used by the Launcher to populate its top-level list.

All activities with filters that match this action and category are added to the list. Asks the activity to display a list of all the notes under content://com.google.provider. The user can then browse through the list and get information about the items in it.

Asks the activity to display a list of the notes under content://com.google.provider. The user can then pick a note from the list, and the activity will return the URI for that item back to the activity that started the NoteList activity. Data type: vnd.android.cursor.

Asks the activity to supply a single item of Note Pad data. The second activity, NoteEditor, shows users a single note entry and allows them to edit it. The first, primary, purpose of this activity is to enable the user to interact with a single note — to either VIEW the note or EDIT it.

(The EDIT_NOTE category is a synonym for EDIT.) The intent would contain the URI for data matching the MIME type vnd.android.cursor. Note — that is, the URI for a single, specific note. It would typically be a URI that was returned by the PICK or GET_CONTENT actions of the NoteList activity.

As before, this filter lists the DEFAULT category so that the activity can be launched by intents that don't explicitly specify the NoteEditor class. The secondary purpose of this activity is to enable the user to create a new note, which it will INSERT into an existing directory of notes. The intent would contain the URI for data matching the MIME type vnd.android.cursor.

Note — that is, the URI for the directory where the note should be placed. Asks the activity to display the content of the note identified by ID. Asks the activity to display the content of the note identified by ID, and to let the user edit it.

If the user saves the changes, the activity updates the data for the note in the content provider. Asks the activity to create a new, empty note in the notes list at content://com.google.provider. NotePad/notes and allow the user to edit it.

If the user saves the note, its URI is returned to the caller. The last activity, TitleEditor, enables the user to edit the title of a note. This could be implemented by directly invoking the activity (by explicitly setting its component name in the Intent), without using an intent filter.

The single intent filter for this activity uses a custom action called "com.android.notepad.action. It must be invoked on a specific note (data type vnd.android.cursor. Note), like the previous VIEW and EDIT actions.

However, here the activity displays the title contained in the note data, not the content of the note itself. In addition to supporting the usual DEFAULT category, the title editor also supports two other standard categories: ALTERNATIVE and SELECTED_ALTERNATIVE. These categories identify activities that can be presented to users in a menu of options (much as the LAUNCHER category identifies activities that should be presented to user in the application launcher).

Note that the filter also supplies an explicit label (via android:label="@string/resolve_title") to better control what users see when presented with this activity as an alternative action to the data they are currently viewing. (For more information on these categories and building options menus, see the PackageManager. QueryIntentActivityOptions() and Menu.

Asks the activity to display the title associated with note ID, and allow the user to edit the title.

Related Questions