Action and category in Androidmanifest.xml

Source: Internet
Author: User

When intent is passed between components, the component needs to use the Intentfilter object if it wants to tell the Android system which intent it can respond to and handle.

The Intentfilter object is responsible for filtering out the intent that the component cannot respond to and handling, and only receives the intent that it cares about. Intentfilter implements the " Whitelist " management, which lists only the intent that the component is willing to accept, but intentfilter only filters the implicit intent, and the explicit intent is transferred directly to the target component. Android components can have one or more intentfilter, each of which is independent of each other and only requires one of the validations to pass through. In addition to the Intentfilter used to filter the broadcast can be created in code , Other intentfilter must be declared in the Androidmanifest.xml file.

Intentfilter with intent corresponding to filter Action , Data and the Category the field, an implicit intent to be processed by a component, must pass the three-link check.

One : Check action (action test)

A <intent-filter> element should contain at least one <action>, otherwise no intent request can match the <intent-filter>.

If the action requested by intent and the <intent-filter> one <action> match, then the intent
After this <intent-filter> 's action test.

If the intent request or <intent-filter> does not specify a specific action type, the following two scenarios occur.

(1) If <intent-filter> does not contain any action type, then no intent request can match this <intent-filter>.

(2) Conversely, if the action type is not set in the intent request, the intent request will pass through <intent-filter> as long as the action type is included in the <intent-filter>. Behavioral tests.

An application can have more than one activity, and each activity is at the same level, which activity is started first when the program is started? Some programs may need to be displayed in the list of programs, some of which are not required. How do you define it? As long as there is such a intent-filter in the XML configuration file, and this launcher,android.intent.action.main determines the activity that the application starts first, Android.intent.category.LAUNCHER determines whether the application appears in the program list. Main and launcher are also set to make sense.

If there is only one activity, no two sentences are allowed.

String add_shortcut_action Action: Adds a shortcut to the system.
String all_apps_action Action: Lists all the available apps. Input: None.
String alternative_category Category: Describes an activity as an optional action for the data that the user is browsing.
String answer_action Action: Handles incoming calls.
String Battery_changed_action Broadcast: The charging state, or the battery's power change.
String Boot_completed_action Broadcast: This action is broadcast once (only once) after the system is started.
String browsable_category Category: Activities that can be used safely by the browser must support this category.
String bug_report_action Action: Displays the activity report error.
String call_action action: Calls are made, and the called contacts are specified in the data.
String Call_forwarding_state_changed_action Broadcast: The call transfer status of a voice call has changed.
String clear_credentials_action Action: Clears the login voucher (credential).
String configuration_changed_action Broadcast: Configuration information for the device has changed, see Resources.configuration.
Creator Creator No No No
String data_activity_state_changed_action Broadcast: The data activity State of the phone (that is, the state of the sending and receiving data) has changed.
String data_connection_state_changed_action Broadcast: The status of the phone's data connection has changed.
String date_changed_action Broadcast: the date is changed.
String default_action Action: The same as View_action, which is the standard action performed on the data.
String default_category Category: This category needs to be set if activity is an option for performing an accurate action on the data (click, center Press).
String delete_action Action: Removes the given data from the container.
String development_preference_category Category: Description activity is a Setup Panel (development PREFERENCE panel).
String dial_action Action: Dials the phone number specified in the data.
String edit_action Action: Displays an editable interface for the data being developed.
String embed_category Category: Ability to run in parent activity.
String emergency_dial_action Action: Call emergency phone number.
int Forward_result_launch boot tag: If the tag is set and is used by an existing activity to initiate a new activity, the activity's reply target (reply target) will be transferred to the new Act Ivity.
String fota_cancel_action Broadcast: Cancels all pending (pending) Update downloads.
String fota_install_action Broadcast: The update has been confirmed and will begin installation immediately.
String fota_ready_action Broadcast: The update has been downloaded and can begin installation.
String Fota_restart_action Broadcast: Restores a stopped update download.
String fota_update_action Broadcast: Download and install OS updates via OTA.
String framework_instrumentation_test_category Category: To is used as code under TEST for FRAMEWORK instrumentation tests.
String gadget_category Category: This activity can be embedded in the host activity (activity that is hosting gadgets).
String get_content_action action: Lets the user select the data and return it.
String home_category Category: Main screen (activity), the first activity that is displayed after the device is started.
String insert_action Action: Inserts an empty item (item) in the container.
String Intent_extra Additional data: When used with Pick_activity_action, describes the ACTIVITY selected by the user to display, and the shortcut to add when used with Add_shortcut_action.
String Label_extra Append Data: A character label that starts with a capital letter, and is used with add_shortcut_action.
String launcher_category Category: Activity should be displayed in the top-level LAUNCHER.
String login_action action: Gets the login credentials.
String main_action action: Starts as the main entry point and does not require data.
String mediabutton_action Broadcast: The user pressed the Media button.
String Media_bad_removal_action Broadcast: The Extended media (expansion card) has been unplugged from the SD card slot, but the mount point has not been lifted (unmount).
String media_eject_action Broadcast: The user wants to remove the extended media (unplug the expansion card).
String Media_mounted_action Broadcast: The extended media is inserted and is already mounted.
String Media_removed_action Broadcast: The extended media is removed.
String media_scanner_finished_action Broadcast: A directory that has been scanned for media.
String media_scanner_started_action Broadcast: A directory that begins scanning media.
String media_shared_action Broadcast: The Mount of the extended media is lifted (unmount) because it has been shared as a USB mass storage.
String Media_unmounted_action Broadcast: The extended media exists but is not mounted (mount).
String message_waiting_state_changed_action Broadcast: Message Waiting (voice mail) status of the phone has changed.
int multiple_task_launch start tag: Used in conjunction with New_task_launch, disables the change of the existing task to the foreground task (foreground).
String network_tickle_received_action Broadcast: The device received a new network "tickle" notification.
int New_task_launch start tag: When set, Activity becomes the first new task (top of the stack) in the history stack.
int No_history_launch start tag: After setting, the new activity is not saved in the history stack.
String package_added_action Broadcast: A new application package is installed on the device.
String package_removed_action Broadcast: An application package was deleted on the device.
String phone_state_changed_action Broadcast: The phone status has changed.
String pick_action Action: Select an item from the data to return the selected item.
String pick_activity_action Action: Select an activity to return the class (name) of the activity selected.
String preference_category Category: Activity is a Setup panel (PREFERENCE panels).
String provider_changed_action Broadcast: The update will be (really) installed.
String Provisioning_check_action Broadcast: Requires polling of PROVISIONING service to download the latest settings.
String run_action Action: Runs the data (the specified app), regardless of what it (APP) is.
String sample_code_category Category: To is used as an a SAMPLE CODE example (not part of the normal user experience).
String screen_off_action Broadcast: The screen is closed.
String screen_on_action Broadcast: The screen has been opened.
String selected_alternative_category Category: Activity is an optional operation for data that is selected by the user.
String sendto_action Action: Sends a message to the recipient specified by data.
String service_state_changed_action Broadcast: The status of the telephony service has changed.
String settings_action Action: Displays system settings. Input: None.
String signal_strength_changed_action Broadcast: The signal strength of the phone has changed.
int Single_top_launch boot tag: After setting, if activity has started and is at the top of the history stack, the activity will no longer start (do not restart).
String Statistics_report_action Broadcast: Requires receivers to report its own statistics.
String statistics_state_changed_action Broadcast: The status of the statistical information Service has changed.
String sync_action Action: Performs data synchronization.
String tab_category Category: This activity should be used as a TAB in tabactivity.
String Template_extra Additional data: The initialization template for the new record.
String test_category Category: Used as a test purpose, is not part of a normal user experience.
String timezone_changed_action Broadcast: The time zone has changed.
String Time_changed_action Broadcast: Time has changed (reset).
String time_tick_action Broadcast: The current time has changed (normal time passes).
String ums_connected_action Broadcast: device enters USB mass storage mode.
String ums_disconnected_action Broadcast: The device exits from USB mass storage mode.
String unit_test_category Category: Should be used as a unit test (run with test harness).
String view_action Action: Displays data to the user.
String wallpaper_category Category: This activity can set the wallpaper for the device.
String wallpaper_changed_action Broadcast: The system's wallpaper has changed.
String wallpaper_settings_action Action: Displays the settings screen for selecting Wallpaper. Input: None.
String web_search_action Action: Performs a WEB search.
String xmpp_connected_action Broadcast: XMPP connection has been established.
String xmpp_disconnected_action Broadcast: XMPP connection has been disconnected.

Note: The activity definition applies filtering as follows

<intent-filter>

<action android:name="Android.intent.action.MAIN" />

</intent-filter>

Two: Check Data (test)

As with action, the data part of Intentfilter can be one or more, and it can not. Each data contains the content of the URL and data type, when the data check is mainly to compare these two points, comparison rule: If a intent object does not set data, only Intentfilter also does not set data to pass the check. If a intent object contains a URI, but does not contain a data type: only if Intentfilter does not specify a data type, and their URI matches, it can pass detection. If a intent object contains a data type, but does not contain a URI: only if Intentfilter does not specify a URL, but only contains the data type and is identical to intent, it passes detection. If a intent object contains both a URI and a data type (or the data type can be inferred from a URI), the intent object can pass the check only if its data type matches the data type in Intentfilter and the URL check is passed.

where the URL consists of four parts : It has four properties scheme, host, port, path corresponding to each part of the URI.

Example: Content://com.wjr.example1:121/files

Scheme section: Content

Host section: Com.wjr.example1

Port section: 121

Path section: Files

The host and Port sections together form the credentials for the URI (authority), and if the host is not specified, the port is ignored.

These four properties are optional, but they are not completely independent. To make authority meaningful, scheme must be specified. To make path interesting, scheme and authority must be specified. Path in Intentfilter can use wildcard characters to match the path field, and both intent and intentfilter can use wildcards to specify MIME types.

Three: Check category Intentfilter (class test)

You can set multiple category,intent or multiple category, and only all the category in intent can match category,intent in Intentfilter to pass the check. That is, if the category collection in intent is a subset of the collection of category in Intentfilter, intent can pass the check. If the category is not set in intent, it can be checked by all Intentfilter category. If a intent is able to pass through the intentfilter of more than one component, the user may be asked to activate the component. If no target is found, an exception is generated.

Category_alternative sets whether the activity can be considered an optional action for the data that the user is viewing
Category_app_browser and Action_main used to launch the browser application
Category_app_calculator and Action_main used to start the calculator application
Category_app_calendar and Action_main used to start the calendar application
Used with Category_app_contacts and Action_main to start a contact application
Used with Category_app_email and action_main to start the mail application
Used with Category_app_gallery and Action_main to launch the gallery application
Used with Category_app_maps and Action_main to launch the map application
Category_app_market This activity allows users to browse and download new applications
Category_app_messaging and Action_main used to start the SMS app
Category_app_music and Action_main used to start the music app
Category_browsable the activity that can be safely invoked by the browser must support this category
Category_default sets whether the activity is optional for the default action
Category_embed can be run within the parent activity container
Category_home main activity, when the application starts, it is the first activity that is displayed
Category_launcher should be displayed in the boot list on the upper level.
Category_monkey This activity may be performed by MONKEY or other automated testing tools.
Category_openable is used to indicate that a get_content intent only wants Contentresolver.openinputstream to open the URI
Category_preference This activity is a tab
Category_sample_code used as a simple code example (not used in general)
Category_selected_alternative sets whether the activity can be considered a selectable action for the data currently selected by the user
Category_tab want to use as a TAB within an existing tabactivity
Category_test for test use (not used in general)
Category_unit_test Joint Test use

What is the purpose of "Android.intent.category.DEFAULT"?

To figure this out, you first need to figure out what is implicit (hidden) Intent what is explicit (explicit) intent.

Explicit Intent explicitly specifies the acitivity to start, such as the following Java code:
Intent intent= New Intent (this, b.class)

Implicit intent does not explicitly specify which activity to start, but instead sets some intent filter to allow the system to filter the appropriate acitivity to start.

Intent exactly which activity to send, need to do three matches, one is action, one is category, one is data.

Theoretically, if intent does not specify category, then whatever the contents of the intent filter should be matched. However, if it is implicit intent,android default to add a category_default, so if intent If the category is not Android.intent.category.DEFAULT in filter, the match test will fail. So, if your activity supports receiving implicit intent, be sure to include Android.intent.category.DEFAULT in intent filter.

Exceptions are: Android.intent.category.MAIN and Android.intent.category.LAUNCHER do not need to join the Android.intent.category.DEFAULT in the filter, of course, not to ask Problem.

We define the activity if accept implicit intent words, intent filer must add android.intent.category.DEFAULT this category.


An explanation from another article:

In writing Androidmanifest.xml, has not understood, when to give Activityandroid.intent.category.DEFAULT filter, now only understand.

--------------------------------------------------------------------------------
Android treats all implicit intents passed to startactivity () as if they contained at least one category: "Android.intent. Category. DEFAULT "(The Category_default constant). Therefore, activities that is willing to receive implicit intents must include ' Android.intent.category.DEFAULT ' in their Intent filters
--------------------------------------------------------------------------------

This means that every implicit Intent that is emitted through the startactivity () method has at least one category, which is "Android.intent.category.DEFAULT", so as long as you want to receive an implicit Intent The Activity should include the "Android.intent.category.DEFAULT" category, otherwise it will cause the intent match to fail.

The following information can also be obtained from the above discussion:
1, a Intent can have more than one category, but there will be at least one, is also the default category.
2, only Intent all category matches, the Activity will receive this Intent.

Category in Android
API Level 3 (SDK 1.5) and API Level 4 (SDK 1.6):
XML code
Android.intent.category.ALTERNATIVE
Android.intent.category.BROWSABLE
Android.intent.category.DEFAULT
Android.intent.category.DEVELOPMENT_PREFERENCE
Android.intent.category.EMBED
Android.intent.category.HOME
Android.intent.category.INFO
Android.intent.category.LAUNCHER
Android.intent.category.MONKEY
Android.intent.category.OPENABLE
Android.intent.category.PREFERENCE
Android.intent.category.SELECTED_ALTERNATIVE
Android.intent.category.TAB

Api Level 5 (SDK 2.0) added:
The XML code
Android.intent.category.CAR_DOCK
Android.intent.category.DESK_DOCK
Api Level 6 and 7 did not change.
Api Level 8 (SDK 2.2) added:
XML code
Android.intent.category.CAR_MODE

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.