关于androidManifest.xml的概叙以及intent-filter的详细分析
AndroidManifest.xml配置文件對于Android應(yīng)用開發(fā)來說是比較細(xì)但又很重要的基礎(chǔ)知識,本文旨在總結(jié)該配置文件中常用到的幾個屬性,以便日后查閱,至于那些比較細(xì)的屬性,主要是平時開發(fā)比較少用便不列舉,如果自己有需要直接在eclipse中直接“alt+/”就好了……
下面是一個比較通用的AndroidManifest.xml文件樣例(所建的工程目錄是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版本的要求 --><uses-sdkandroid:minSdkVersion="14"android:targetSdkVersion="21" /><!-- 獲取系統(tǒng)相關(guān)的權(quán)限配置 如果不知道系統(tǒng)有多少屬性,不用那么麻煩去搜,直接在name便簽的雙引號里alt+/就好,多直接~ --><uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/><!-- 應(yīng)用配置細(xì)節(jié)icon是圖標(biāo);
label是程序名稱顯示在titlebar中的
theme是整個程序的主題,這里是自己文件定義的主題,如果想用android的就是@android:style/Theme再加alt+/就可以隨便選了
--><applicationandroid:allowBackup="true"android:icon="@drawable/ic_launcher"android:label="@string/app_name"android:theme="@style/AppTheme" >
<!-- Activity配置 --><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配置 --><service ><intent-filter ><action /><category /><data /></intent-filter></service><!-- Receive配置 --><receiver ><intent-filter /><meta-data /></receiver><!-- Provider配置 --><provider ><grant-uri-permission /><meta-data /><path-permission /></provider><!-- 程序需要的外部庫 --><uses-library /></application></manifest>
?
? ? ?縱觀上面的各個系統(tǒng)組件配置,基本都有一個Intent-filter屬性,來對系統(tǒng)中各種亂七八糟的intent進(jìn)行過濾處理。因為android系統(tǒng)中會時時刻刻發(fā)送著各種消息各種intent,有些是系統(tǒng)發(fā)的有些是各個程序發(fā)的,怎么從那么多的消息中獲取自己想要的?那就過濾,Intent-filter就是起這個作用。下面我們來詳細(xì)問題一下這個Intent-filter的相關(guān)屬性,雖然各個組件的Intent-filter有差別,但是了解大概后,基本都差不多,舉一反三,觸類旁通嘛。
? ? ?Intent消息還包含有名稱、動作、數(shù)據(jù)、類別幾個重要屬性,同時這幾個點(diǎn)因過濾的標(biāo)簽的不同而有一些差別。
<action>標(biāo)簽用于描述具體消息的名稱;
<category>標(biāo)簽用于表示能處理消息組件的類別;
<data>標(biāo)簽則用于描述消息需要處理的數(shù)據(jù)格式,支持使用正則表達(dá)式來限定數(shù)據(jù)來源;
例如以下是一個activity的intent-filter:
<intent-filter> <action android:name="wytings msg" /> <category android:name="android.intent.category.DEFAULT" /> <data mimeType="*/*" /> </intent-filter>只要系統(tǒng)中有程序發(fā)出的intent的action為wytings msg這個activity就可以收到。
category設(shè)置的是默認(rèn)配置,一般category主要就是android.intent.category.DEFAULT和android.intent.category.LAUNCHER兩個(前者是默認(rèn)配置,看action怎么設(shè)置,就怎么啟動,后者是代表的第一個啟動的基本都得和<action android:name="android.intent.action.MAIN" />一起用),其他的看自己需求,要是還是不知道還是alt+/就好了。
data中設(shè)置了處理類型,意思就是消息我收到了,如果不是我處理的類型,我依然不干活。比如我們把上面的action設(shè)置為android.intent.action.SEND(意思是當(dāng)我們點(diǎn)發(fā)送的時候,系統(tǒng)就會調(diào)用這個activity,還有個前提是發(fā)送的文件得是它支持的,這里是什么都文件類型都支持)
?
轉(zhuǎn)載于:https://www.cnblogs.com/wytings/p/4083463.html
總結(jié)
以上是生活随笔為你收集整理的关于androidManifest.xml的概叙以及intent-filter的详细分析的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 文本读取写入易错问题
- 下一篇: hdu 5100 n*n棋盘放k*1长方