For more information about androidManifest. xml and the analysis of intent-filter, androidmanifest

Source: Internet
Author: User

For more information about androidManifest. xml and the analysis of intent-filter, androidmanifest

AndroidManifest. the xml configuration file is a relatively fine but important basic knowledge for Android Application Development. This article aims to summarize several attributes commonly used in this configuration file for future reference, as for the finer attributes, we usually choose not to list them when there are few developers at ordinary times. If you need to directly "alt +/" in eclipse, that would be fine ......

The following is a general example of AndroidManifest. xml file (the project directory is Test ),

<? Xml version = "1.0" encoding = "UTF-8"?> <Manifest xmlns: android = "http://schemas.android.com/apk/res/android" package = "com. example. test" android: versionCode = "1" android: versionName = "1.0"> <! -- SDK version requirements --> <uses-sdk android: minSdkVersion = "14" android: targetSdkVersion = "21"/> <! -- Obtain the system-related permission configuration. If you do not know how many attributes the system has, you do not need to search for them. You can simply alt +/in the double quotation marks of the name tab ~ --> <Uses-permission android: name = "android. permission. ACCESS_WIFI_STATE"/> <! -- Application configuration details
Icon is an icon;
Label is the program name displayed in titlebar
Theme is the topic of the entire program. Here it is the topic defined in your own file. If you want to use android, @ android: style/Theme and alt +/can be selected at will.
--> <Application android: allowBackup = "true" android: icon = "@ drawable/ic_launcher" android: label = "@ string/app_name" android: theme = "@ style/AppTheme">
<! -- Activity configuration --> <activity
Android: name = ". mainActivity "android: label =" @ string/app_name "> <intent-filter> <action android: name =" android. intent. action. MAIN "/> <category android: name =" android. intent. category. LAUNCHER "/> <data android: host =" MainActivity "/> </intent-filter> </activity> <! -- Service configuration --> <service> <intent-filter> <action/> <category/> <data/> </intent-filter> </service> <! -- Receive configuration --> <receiver ER> <intent-filter/> <meta-data/> </receiver ER> <! -- Provider configuration --> <provider> <grant-uri-permission/> <meta-data/> <path-permission/> </provider> <! -- External library required by the program --> <uses-library/> </application> </manifest>

 

Throughout the configuration of various system components above, there is basically an Intent-filter attribute to filter various messy intents in the system. Because the android system always sends a variety of intent messages, some of which are sent by various programs, how to get what you want from so many messages? Then filter. Intent-filter plays this role. Next, let's take a look at the relevant attributes of the Intent-filter. Although the Intent-filter of each component is different, it is almost the same after understanding it.

Intent messages also contain several important attributes, such as name, action, data, and category. At the same time, these vertices vary depending on the tags to be filtered.

<Action> A tag is used to describe the name of a specific message;

<Category> tags are used to indicate the types of message components that can be processed;

<Data> tags are used to describe the data format to be processed by a message. You can use regular expressions to limit the data source;

For example, the following is the intent-filter of an activity:

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

As long as the intent action sent by the program in the system is wyw.msg, this activity can be received.

The default configuration is set for category. Generally, category is mainly set for android. intent. category. DEFAULT and android. intent. category. LAUNCHER (the former is the default configuration. You can set the action to start it. The latter represents the first startup, which is basically the same as <action android: name = "android. intent. action. MAIN "/> used together). If you still don't know whether to use alt +/, you just need to consider your needs.

The processing type is set in data, which means that the message is received. If it is not my processing type, I still do not work. For example, we set the above action to android. intent. action. SEND)

 


Android beginners help multiple intent-filter attributes in AndroidManifestxml, how to distinguish which is the main entry

An application can have multiple activities, each of which is at the same level. Which Activity is the first to start when a program is started? Some programs may need to be displayed in the program list, while others do not. How to define it? Android. intent. action. MAIN determines the Activity that the application starts first.
, Android. intent. category. LAUNCHER determines whether the application is displayed in the program list. It makes sense to set both Main and LAUNCHER,

If multiple same-level activities have filters

<Intent-filter>
<Action android: name = "android. intent. action. MAIN"/>
<Category android: name = "android. intent. category. LAUNCHER"/>
</Intent-filter>

Only the <action
Android: name = "android. intent. action. MAIN"
/> Valid. The Activity is executed when the program is started. There are multiple icons in the program list. These activities are displayed in the program list. This Application has multiple entries to execute different activities, however, the main entrance of the entire program (the activity that runs the whole program first) has only the Activity that is defined first.

If an application does not have a LAUNCHER, the apk can still be installed on the device, but cannot be seen in the main program diagram. If you give the Activity
If LAUNCHER is set and Main is set at the same time, the Activity can be displayed in the program diagram. If Main is not set, no Activity is started, and no icon is displayed.

When Android is developed, there is a <intent-filter> in the Manifest file that contains <action> and <category>

Android. intent. action. MAIN
Determines the Activity that the application starts first.
Android. intent. category. LAUNCHER
Determines whether the application is displayed in the program list.
Score ~~~

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.