Android Manifest.xml 之 Intent-filter

來源:互聯網
上載者:User

標籤:des   android   c   style   class   blog   

開始前先post出最簡單的AndroidManifest.xml檔案:

<?xml version="1.0" encoding="UTF-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android"    package="com.example.android.actionbarcompat.basic"    android:versionCode="1"    android:versionName="1.0">     <!-- ActionBarCompat provides an Action Bar from API v7 onwards -->    <uses-sdk        android:minSdkVersion="7"        android:targetSdkVersion="17" />     <application        android:icon="@drawable/ic_launcher"        android:label="@string/app_name"        android:theme="@style/Theme.AppCompat"        android:allowBackup="true">         <activity android:name=".MainActivity">            <!-- Launcher Intent filter -->            <intent-filter>                <action android:name="android.intent.action.MAIN" />                <category android:name="android.intent.category.LAUNCHER" />            </intent-filter>        </activity>    </application> </manifest>

  Android核心組件(Activity,Service,Broadcast Receiver)通過Intent來啟用,Intent描述了actioin,data等資訊;在某個component被啟用前,要提前寫好該component能處理那些Intent,這就需要在AndroidManifest.xml 裡<intent-filter></intent-filter>標籤內寫好。

      <intent-filter>...</intent-filter>省略符號可以有以下內容:

      

  • action -- The general action to be performed, such as ACTION_VIEWACTION_EDITACTION_MAIN, etc.

  • data -- The data to operate on, such as a person record in the contacts database, expressed as a Uri.

  • category -- Gives additional information about the action to execute. For example, CATEGORY_LAUNCHER means it should appear in the Launcher as a top-level application, while CATEGORY_ALTERNATIVE means it should be included in a list of alternative actions the user can perform on a piece of data.

  • type -- Specifies an explicit type (a MIME type) of the intent data. Normally the type is inferred from the data itself. By setting this attribute, you disable that evaluation and force an explicit type.

  • component -- Specifies an explicit name of a component class to use for the intent. Normally this is determined by looking at the other information in the intent (the action, data/type, and categories) and matching that with a component that can handle it. If this attribute is set then none of the evaluation is performed, and this component is used exactly as is. By specifying this attribute, all of the other Intent attributes become optional.

  • extras -- This is a Bundle of any additional information. This can be used to provide extended information to the component. For example, if we have a action to send an e-mail message, we could also include extra pieces of data here to supply a subject, body, etc.

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.