Android之AndroidManifest.xml文件解析和权限集合
一、關(guān)于AndroidManifest.xml
AndroidManifest.xml 是每個android程序中必須的文件。它位于整個項目的根目錄,描述了package中暴露的組件(activities, services, 等等),他們各自的實現(xiàn)類,各種能被處理的數(shù)據(jù)和啟動位置。 除了能聲明程序中的Activities, ContentProviders, Services, 和Intent Receivers,還能指定permissions和instrumentation(安全控制和測試)
二、AndroidManifest.xml結(jié)構(gòu)
<?xmlversion="1.0"encoding="utf-8"?><manifest><application><activity><intent-filter><action/><category/></intent-filter></activity><activity-alias><intent-filter></intent-filter><meta-data/></activity-alias><service><intent-filter></intent-filter><meta-data/></service><receiver><intent-filter></intent-filter><meta-data/></receiver><provider><grant-uri-permission/><meta-data/></provider><uses-library/></application><uses-permission/><permission/><permission-tree/><permission-group/><instrumentation/><uses-sdk/><uses-configuration/> <uses-feature/> <supports-screens/></manifest>三、各個節(jié)點的詳細介紹
?上面就是整個am(androidManifest).xml的結(jié)構(gòu),下面以外向內(nèi)開始闡述~~
1、第一層(<Manifest>):(屬性)
<manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.woody.test"android:sharedUserId="string"android:sharedUserLabel="string resource"android:versionCode="integer"android:versionName="string"android:installLocation=["auto" | "internalOnly" | "preferExternal"] > </manifest>A、xmlns:android
定義android命名空間,一般為http://schemas.android.com/apk/res/android,這樣使得Android中各種標準屬性能在文件中使用,提供了大部分元素中的數(shù)據(jù)。
B、package
指定本應(yīng)用內(nèi)java主程序包的包名,它也是一個應(yīng)用進程的默認名稱
C、sharedUserId
表明數(shù)據(jù)權(quán)限,因為默認情況下,Android給每個APK分配一個唯一的UserID,所以是默認禁止不同APK訪問共享數(shù)據(jù)的。若要共享數(shù)據(jù),第一可以采用Share Preference方法,第二種就可以采用sharedUserId了,將不同APK的sharedUserId都設(shè)為一樣,則這些APK之間就可以互相共享數(shù)據(jù)了。詳見:http://wallage.blog.163.com/blog/static/17389624201011010539408/
D、sharedUserLabel
一個共享的用戶名,它只有在設(shè)置了sharedUserId屬性的前提下才會有意義
E、versionCode
是給設(shè)備程序識別版本(升級)用的必須是一個interger值代表app更新過多少次,比如第一版一般為1,之后若要更新版本就設(shè)置為2,3等等。。。
F、versionName
這個名稱是給用戶看的,你可以將你的APP版本號設(shè)置為1.1版,后續(xù)更新版本設(shè)置為1.2、2.0版本等等。。。
G、installLocation
安裝參數(shù),是Android2.2中的一個新特性,installLocation有三個值可以選擇:internalOnly、auto、preferExternal
選擇preferExternal,系統(tǒng)會優(yōu)先考慮將APK安裝到SD卡上(當(dāng)然最終用戶可以選擇為內(nèi)部ROM存儲上,如果SD存儲已滿,也會安裝到內(nèi)部存儲上)
選擇auto,系統(tǒng)將會根據(jù)存儲空間自己去適應(yīng)
選擇internalOnly是指必須安裝到內(nèi)部才能運行
(注:需要進行后臺類監(jiān)控的APP最好安裝在內(nèi)部,而一些較大的游戲APP最好安裝在SD卡上。現(xiàn)默認為安裝在內(nèi)部,如果把APP安裝在SD卡上,首先得設(shè)置你的level為8,并且要配置android:installLocation這個參數(shù)的屬性為preferExternal)
2、第二層(<Application>):屬性
一個AndroidManifest.xml中必須含有一個Application標簽,這個標簽聲明了每一個應(yīng)用程序的組件及其屬性(如icon,label,permission等)
<application android:allowClearUserData=["true" | "false"]android:allowTaskReparenting=["true" | "false"]android:backupAgent="string"android:debuggable=["true" | "false"]android:description="string resource"android:enabled=["true" | "false"]android:hasCode=["true" | "false"]android:icon="drawable resource"android:killAfterRestore=["true" | "false"]android:label="string resource"android:manageSpaceActivity="string"android:name="string"android:permission="string"android:persistent=["true" | "false"]android:process="string"android:restoreAnyVersion=["true" | "false"]android:taskAffinity="string"android:theme="resource or theme" > </application>A、android:allowClearUserData('true' or 'false')
用戶是否能選擇自行清除數(shù)據(jù),默認為true,程序管理器包含一個選擇允許用戶清除數(shù)據(jù)。當(dāng)為true時,用戶可自己清理用戶數(shù)據(jù),反之亦然
B、android:allowTaskReparenting('true' or 'false')
是否允許activity更換從屬的任務(wù),比如從短信息任務(wù)切換到瀏覽器任務(wù)
C、android:backupAgent
這也是Android2.2中的一個新特性,設(shè)置該APP的備份,屬性值應(yīng)該是一個完整的類名,如com.project.TestCase,此屬性并沒有默認值,并且類名必須得指定(就是個備份工具,將數(shù)據(jù)備份到云端的操作)
D、android:debuggable
這個從字面上就可以看出是什么作用的,當(dāng)設(shè)置為true時,表明該APP在手機上可以被調(diào)試。默認為false,在false的情況下調(diào)試該APP,就會報以下錯誤:
Device XXX requires that applications explicitely declare themselves as debuggable in their manifest.
?Application XXX does not have the attribute 'debuggable' set to TRUE in its manifest and cannot be debugged.
E、android:description/android:label
此兩個屬性都是為許可提供的,均為字符串資源,當(dāng)用戶去看許可列表(android:label)或者某個許可的詳細信息(android:description)時,這些字符串資源就可以顯示給用戶。label應(yīng)當(dāng)盡量簡短,之需要告知用戶該許可是在保護什么功能就行。而description可以用于具體描述獲取該許可的程序可以做哪些事情,實際上讓用戶可以知道如果他們同意程序獲取該權(quán)限的話,該程序可以做什么。我們通常用兩句話來描述許可,第一句描述該許可,第二句警告用戶如果批準該權(quán)限會可能有什么不好的事情發(fā)生
F、android:enabled
Android系統(tǒng)是否能夠?qū)嵗搼?yīng)用程序的組件,如果為true,每個組件的enabled屬性決定那個組件是否可以被 enabled。如果為false,它覆蓋組件指定的值;所有組件都是disabled。
G、android:hasCode('true' or 'false')
表示此APP是否包含任何的代碼,默認為true,若為false,則系統(tǒng)在運行組件時,不會去嘗試加載任何的APP代碼
一個應(yīng)用程序自身不會含有任何的代碼,除非內(nèi)置組件類,比如Activity類,此類使用了AliasActivity類,當(dāng)然這是個罕見的現(xiàn)象
(在Android2.3可以用標準C來開發(fā)應(yīng)用程序,可在androidManifest.xml中將此屬性設(shè)置為false,因為這個APP本身已經(jīng)不含有任何的JAVA代碼了)
H、android:icon
這個很簡單,就是聲明整個APP的圖標,圖片一般都放在drawable文件夾下
I、android:killAfterRestore
J、android:manageSpaceActivity
K、android:name
為應(yīng)用程序所實現(xiàn)的Application子類的全名。當(dāng)應(yīng)用程序進程開始時,該類在所有應(yīng)用程序組件之前被實例化。
若該類(比方androidMain類)是在聲明的package下,則可以直接聲明android:name="androidMain",但此類是在package下面的子包的話,就必須聲明為全路徑或android:name="package名稱.子包名成.androidMain"
L、android:permission
設(shè)置許可名,這個屬性若在<application>上定義的話,是一個給應(yīng)用程序的所有組件設(shè)置許可的便捷方式,當(dāng)然它是被各組件設(shè)置的許可名所覆蓋的
M、android:presistent
該應(yīng)用程序是否應(yīng)該在任何時候都保持運行狀態(tài),默認為false。因為應(yīng)用程序通常不應(yīng)該設(shè)置本標識,持續(xù)模式僅僅應(yīng)該設(shè)置給某些系統(tǒng)應(yīng)用程序才是有意義的。
N、android:process
應(yīng)用程序運行的進程名,它的默認值為<manifest>元素里設(shè)置的包名,當(dāng)然每個組件都可以通過設(shè)置該屬性來覆蓋默認值。如果你想兩個應(yīng)用程序共用一個進程的話,你可以設(shè)置他們的android:process相同,但前提條件是他們共享一個用戶ID及被賦予了相同證書的時候
O、android:restoreAnyVersion
同樣也是android2.2的一個新特性,用來表明應(yīng)用是否準備嘗試恢復(fù)所有的備份,甚至該備份是比當(dāng)前設(shè)備上更要新的版本,默認是false
P、android:taskAffinity
擁有相同的affinity的Activity理論上屬于相同的Task,應(yīng)用程序默認的affinity的名字是<manifest>元素中設(shè)定的package名
Q、android:theme
是一個資源的風(fēng)格,它定義了一個默認的主題風(fēng)格給所有的activity,當(dāng)然也可以在自己的theme里面去設(shè)置它,有點類似style。
3、第三層(<Activity>):屬性
<activity android:allowTaskReparenting=["true" | "false"]android:alwaysRetainTaskState=["true" | "false"]android:clearTaskOnLaunch=["true" | "false"]android:configChanges=["mcc", "mnc", "locale","touchscreen", "keyboard", "keyboardHidden","navigation", "orientation", "screenLayout","fontScale", "uiMode"]android:enabled=["true" | "false"]android:excludeFromRecents=["true" | "false"]android:exported=["true" | "false"]android:finishOnTaskLaunch=["true" | "false"]android:icon="drawable resource"android:label="string resource"android:launchMode=["multiple" | "singleTop" |"singleTask" | "singleInstance"]android:multiprocess=["true" | "false"]android:name="string"android:noHistory=["true" | "false"] android:permission="string"android:process="string"android:screenOrientation=["unspecified" | "user" | "behind" |"landscape" | "portrait" |"sensor" | "nosensor"]android:stateNotNeeded=["true" | "false"]android:taskAffinity="string"android:theme="resource or theme"android:windowSoftInputMode=["stateUnspecified","stateUnchanged", "stateHidden","stateAlwaysHidden", "stateVisible","stateAlwaysVisible", "adjustUnspecified","adjustResize", "adjustPan"] > </activity>(注:有些在application中重復(fù)的就不多闡述了)
1、android:alwaysRetainTaskState
?是否保留狀態(tài)不變, 比如切換回home, 再從新打開,activity處于最后的狀態(tài)。比如一個瀏覽器擁有很多狀態(tài)(當(dāng)打開了多個TAB的時候),用戶并不希望丟失這些狀態(tài)時,此時可將此屬性設(shè)置為true
2、android:clearTaskOnLaunch
比如 P 是 activity, Q 是被P 觸發(fā)的 activity, 然后返回Home, 重新啟動 P,是否顯示 Q
3、android:configChanges
當(dāng)配置list發(fā)生修改時, 是否調(diào)用 onConfigurationChanged() 方法? 比如 "locale|navigation|orientation".
這個我用過,主要用來看手機方向改變的. android手機在旋轉(zhuǎn)后,layout會重新布局, 如何做到呢?
正常情況下. 如果手機旋轉(zhuǎn)了.當(dāng)前Activity后殺掉,然后根據(jù)方向重新加載這個Activity. 就會從onCreate開始重新加載.
如果你設(shè)置了 這個選項, 當(dāng)手機旋轉(zhuǎn)后,當(dāng)前Activity之后調(diào)用onConfigurationChanged() 方法. 而不跑onCreate方法等.
4、android:excludeFromRecents
是否可被顯示在最近打開的activity列表里,默認是false
5、android:finishOnTaskLaunch
當(dāng)用戶重新啟動這個任務(wù)的時候,是否關(guān)閉已打開的activity,默認是false
如果這個屬性和allowTaskReparenting都是true,這個屬性就是王牌。Activity的親和力將被忽略。該Activity已經(jīng)被摧毀并非re-parented
6、android:launchMode(Activity加載模式)
在多Activity開發(fā)中,有可能是自己應(yīng)用之間的Activity跳轉(zhuǎn),或者夾帶其他應(yīng)用的可復(fù)用Activity。可能會希望跳轉(zhuǎn)到原來某個Activity實例,而不是產(chǎn)生大量重復(fù)的Activity。這需要為Activity配置特定的加載模式,而不是使用默認的加載模式
Activity有四種加載模式:
standard、singleTop、singleTask、singleInstance(其中前兩個是一組、后兩個是一組),默認為standard
?
standard:就是intent將發(fā)送給新的實例,所以每次跳轉(zhuǎn)都會生成新的activity。
singleTop:也是發(fā)送新的實例,但不同standard的一點是,在請求的Activity正好位于棧頂時(配置成singleTop的Activity),不會構(gòu)造新的實例
singleTask:和后面的singleInstance都只創(chuàng)建一個實例,當(dāng)intent到來,需要創(chuàng)建設(shè)置為singleTask的Activity的時候,系統(tǒng)會檢查棧里面是否已經(jīng)有該Activity的實例。如果有直接將intent發(fā)送給它。
singleInstance:
首先說明一下task這個概念,Task可以認為是一個棧,可放入多個Activity。比如啟動一個應(yīng)用,那么Android就創(chuàng)建了一個Task,然后啟動這個應(yīng)用的入口Activity,那在它的界面上調(diào)用其他的Activity也只是在這個task里面。那如果在多個task中共享一個Activity的話怎么辦呢。舉個例來說,如果開啟一個導(dǎo)游服務(wù)類的應(yīng)用程序,里面有個Activity是開啟GOOGLE地圖的,當(dāng)按下home鍵退回到主菜單又啟動GOOGLE地圖的應(yīng)用時,顯示的就是剛才的地圖,實際上是同一個Activity,實際上這就引入了singleInstance。singleInstance模式就是將該Activity單獨放入一個棧中,這樣這個棧中只有這一個Activity,不同應(yīng)用的intent都由這個Activity接收和展示,這樣就做到了共享。當(dāng)然前提是這些應(yīng)用都沒有被銷毀,所以剛才是按下的HOME鍵,如果按下了返回鍵,則無效
7、android:multiprocess
是否允許多進程,默認是false
具體可看該篇文章:http://www.bangchui.org/simple/?t3181.html
8、android:noHistory
當(dāng)用戶從Activity上離開并且它在屏幕上不再可見時,Activity是否從Activity stack中清除并結(jié)束。默認是false。Activity不會留下歷史痕跡
9、android:screenOrientation
activity顯示的模式
默認為unspecified:由系統(tǒng)自動判斷顯示方向
landscape橫屏模式,寬度比高度大
portrait豎屏模式, 高度比寬度大
user模式,用戶當(dāng)前首選的方向
behind模式:和該Activity下面的那個Activity的方向一致(在Activity堆棧中的)
sensor模式:有物理的感應(yīng)器來決定。如果用戶旋轉(zhuǎn)設(shè)備這屏幕會橫豎屏切換
nosensor模式:忽略物理感應(yīng)器,這樣就不會隨著用戶旋轉(zhuǎn)設(shè)備而更改了
10、android:stateNotNeeded
activity被銷毀或者成功重啟時是否保存狀態(tài)
11、android:windowSoftInputMode
activity主窗口與軟鍵盤的交互模式,可以用來避免輸入法面板遮擋問題,Android1.5后的一個新特性。
這個屬性能影響兩件事情:
【A】當(dāng)有焦點產(chǎn)生時,軟鍵盤是隱藏還是顯示
【B】是否減少活動主窗口大小以便騰出空間放軟鍵盤
各值的含義:
【A】stateUnspecified:軟鍵盤的狀態(tài)并沒有指定,系統(tǒng)將選擇一個合適的狀態(tài)或依賴于主題的設(shè)置
【B】stateUnchanged:當(dāng)這個activity出現(xiàn)時,軟鍵盤將一直保持在上一個activity里的狀態(tài),無論是隱藏還是顯示
【C】stateHidden:用戶選擇activity時,軟鍵盤總是被隱藏
【D】stateAlwaysHidden:當(dāng)該Activity主窗口獲取焦點時,軟鍵盤也總是被隱藏的
【E】stateVisible:軟鍵盤通常是可見的
【F】stateAlwaysVisible:用戶選擇activity時,軟鍵盤總是顯示的狀態(tài)
【G】adjustUnspecified:默認設(shè)置,通常由系統(tǒng)自行決定是隱藏還是顯示
【H】adjustResize:該Activity總是調(diào)整屏幕的大小以便留出軟鍵盤的空間
【I】adjustPan:當(dāng)前窗口的內(nèi)容將自動移動以便當(dāng)前焦點從不被鍵盤覆蓋和用戶能總是看到輸入內(nèi)容的部分
4、第四層(<intent-filter>)
結(jié)構(gòu)圖:
<intent-filter? android:icon="drawable resource"
?????????????? android:label="string resource"
?????????????? android:priority="integer" >
????? <action />
????? <category />
????? <data />
</intent-filter>
?
intent-filter屬性
android:priority(解釋:有序廣播主要是按照聲明的優(yōu)先級別,如A的級別高于B,那么,廣播先傳給A,再傳給B。優(yōu)先級別就是用設(shè)置priority屬性來確定,范圍是從-1000~1000,數(shù)越大優(yōu)先級別越高)
Intent filter內(nèi)會設(shè)定的資料包括action,data與category三種。也就是說filter只會與intent里的這三種資料作對比動作
action屬性
action很簡單,只有android:name這個屬性。常見的android:name值為android.intent.action.MAIN,表明此activity是作為應(yīng)用程序的入口。有關(guān)android:name具體有哪些值,可參照這個網(wǎng)址:http://hi.baidu.com/linghtway/blog/item/83713cc1c2d053170ff477a7.html
category屬性
category也只有android:name屬性。常見的android:name值為android.intent.category.LAUNCHER(決定應(yīng)用程序是否顯示在程序列表里)
有關(guān)android:name具體有哪些值,可參照這個網(wǎng)址:http://chroya.javaeye.com/blog/685871
data屬性
<data? android:host="string"
????? android:mimeType="string"
????? android:path="string"
????? android:pathPattern="string"
????? android:pathPrefix="string"
????? android:port="string"
????? android:scheme="string"/>
【1】每個<data>元素指定一個URI和數(shù)據(jù)類型(MIME類型)。它有四個屬性scheme、host、port、path對應(yīng)于URI的每個部分:
scheme://host:port/path
scheme的值一般為"http",host為包名,port為端口號,path為具體地址。如:http://com.test.project:200/folder/etc
其中host和port合起來構(gòu)成URI的憑據(jù)(authority),如果host沒有指定,則port也會被忽略
要讓authority有意義,scheme也必須要指定。要讓path有意義,scheme+authority也必須要指定
【2】mimeType(指定數(shù)據(jù)類型),若mimeType為'Image',則會從content Provider的指定地址中獲取image類型的數(shù)據(jù)。還有'video'啥的,若設(shè)置為video/mp4,則表示在指定地址中獲取mp4格式的video文件
【3】而pathPattern和PathPrefix主要是為了格式化path所使用的
5、第四層<meta-data>
<meta-data android:name="string"
?????????? android:resource="resource specification"
?????????? android:value="string"/>
這是該元素的基本結(jié)構(gòu).可以包含在<activity> <activity-alias> <service> <receiver>四個元素中。
android:name(解釋:元數(shù)據(jù)項的名字,為了保證這個名字是唯一的,采用java風(fēng)格的命名規(guī)范,如com.woody.project.fried)
android:resource(解釋:資源的一個引用,指定給這個項的值是該資源的id。該id可以通過方法Bundle.getInt()來從meta-data中找到。)
android:value(解釋:指定給這一項的值。可以作為值來指定的數(shù)據(jù)類型并且組件用來找回那些值的Bundle方法:[getString],[getInt],[getFloat],[getString],[getBoolean])
6、第三層<activity-alias>屬性
<activity-alias android:enabled=["true" | "false"]
??????????????? android:exported=["true" | "false"]
??????????????? android:icon="drawable resource"
??????????????? android:label="string resource"
??????????????? android:name="string"
??????????????? android:permission="string"
??????????????? android:targetActivity="string">
<intent-filter/>
<meta-data/>
</activity-alias>
<activity-alias>是為activity創(chuàng)建快捷方式的,如下實例:
<activity android:name=".shortcut">
??????????? <intent-filter>
??????????????? <action android:name="android.intent.action.MAIN" />
??????????? </intent-filter>
</activity>
?<activity-alias android:name=".CreateShortcuts" android:targetActivity=".shortcut" android:label="@string/shortcut">
??? <intent-filter>
???????????? <action android:name="android.intent.action.CREATE_SHORTCUT" />
???????????? <category android:name="android.intent.category.DEFAULT" />
???? </intent-filter>
?</activity-alias>
其中android.targetActivity是指向?qū)?yīng)快捷方式的activity,如上述的shortcut(此Activity名)
android:label是指快捷方式的名稱,而快捷方式的圖標默認是給定的application圖標
7、第三層<service>
【1】service與activity同級,與activity不同的是,它不能自己啟動的,運行在后臺的程序,如果我們退出應(yīng)用時,Service進程并沒有結(jié)束,它仍然在后臺運行。比如聽音樂,網(wǎng)絡(luò)下載數(shù)據(jù)等,都是由service運行的
【2】service生命周期:Service只繼承了onCreate(),onStart(),onDestroy()三個方法,第一次啟動Service時,先后調(diào)用了onCreate(),onStart()這兩個方法,當(dāng)停止Service時,則執(zhí)行onDestroy()方法,如果Service已經(jīng)啟動了,當(dāng)我們再次啟動Service時,不會在執(zhí)行onCreate()方法,而是直接執(zhí)行onStart()方法
【3】service與activity間的通信
Service后端的數(shù)據(jù)最終還是要呈現(xiàn)在前端Activity之上的,因為啟動Service時,系統(tǒng)會重新開啟一個新的進程,這就涉及到不同進程間通信的問題了(AIDL),Activity與service間的通信主要用IBinder負責(zé)。具體可參照:http://zhangyan1158.blog.51cto.com/2487362/491358
【4】
<service android:enabled=["true" | "false"]
???????? android:exported[="true" | "false"]
???????? android:icon="drawable resource"
???????? android:label="string resource"
???????? android:name="string"
???????? android:permission="string"
???????? android:process="string">
</service>
service標簽內(nèi)的屬性之前已有描述,在此不重復(fù)了~
8、第三層<receiver>
receiver的屬性與service一樣,這里就不顯示了
BroadcastReceiver:用于發(fā)送廣播,broadcast是在應(yīng)用程序之間傳輸信息的一種機制,而BroadcastReceiver是對發(fā)送出來的 Broadcast進行過濾接受并響應(yīng)的一類組件,具體參照http://kevin2562.javaeye.com/blog/686787
9、第三層<provider>屬性
<provider android:authorities="list"
????????? android:enabled=["true" | "false"]
????????? android:exported=["true" | "false"]
????????? android:grantUriPermissions=["true" | "false"]
????????? android:icon="drawable resource"
????????? android:initOrder="integer"
????????? android:label="string resource"
????????? android:multiprocess=["true" | "false"]
????????? android:name="string"
????????? android:permission="string"
????????? android:process="string"
????????? android:readPermission="string"
????????? android:syncable=["true" | "false"]
????????? android:writePermission="string">
?????????? <grant-uri-permission/>
?????????? <meta-data/>
</provider>
contentProvider(數(shù)據(jù)存儲)
【1】android:authorities:
標識這個ContentProvider,調(diào)用者可以根據(jù)這個標識來找到它
【2】android:grantUriPermission:
對某個URI授予的權(quán)限
【3】android:initOrder
10、第三層<uses-library>
用戶庫,可自定義。所有android的包都可以引用
11、第一層<supports-screens>
<supports-screens? android:smallScreens=["true" | "false"]
????????????????? android:normalScreens=["true" | "false"]
????????????????? android:largeScreens=["true" | "false"]
????????????????? android:anyDensity=["true" | "false"] />
這是在android1.6以后的新特性,支持多屏幕機制
各屬性含義:這四個屬性,是否支持大屏,是否支持中屏,是否支持小屏,是否支持多種不同密度
12、第二層<uses-configuration />與<uses-feature>性能都差不多
<uses-configuration? android:reqFiveWayNav=["true" | "false"]
??????????????????? android:reqHardKeyboard=["true" | "false"]
??????????????????? android:reqKeyboardType=["undefined" | "nokeys" | "qwerty" |?? "twelvekey"]
??????????????????? android:reqNavigation=["undefined" | "nonav" | "dpad" |? "trackball" | "wheel"]
??????????????????? android:reqTouchScreen=["undefined" | "notouch" | "stylus" | "finger"] />
<uses-feature android:glEsVersion="integer"
????????????? android:name="string"
????????????? android:required=["true" | "false"] />
這兩者都是在描述應(yīng)用所需要的硬件和軟件特性,以便防止應(yīng)用在沒有這些特性的設(shè)備上安裝。
13、第二層<uses-sdk />
<uses-sdk android:minSdkVersion="integer"
????????? android:targetSdkVersion="integer"
????????? android:maxSdkVersion="integer"/>
描述應(yīng)用所需的api level,就是版本,目前是android 2.2 = 8,android2.1 = 7,android1.6 = 4,android1.5=3
在此屬性中可以指定支持的最小版本,目標版本以及最大版本
14、第二層<instrumentation />
<instrumentation android:functionalTest=["true" | "false"]
???????????????? android:handleProfiling=["true" | "false"]
???????????????? android:icon="drawable resource"
???????????????? android:label="string resource"
???????????????? android:name="string"
???????????????? android:targetPackage="string"/>
?定義一些用于探測和分析應(yīng)用性能等等相關(guān)的類,可以監(jiān)控程序。在各個應(yīng)用程序的組件之前instrumentation類被實例化
android:functionalTest(解釋:instrumentation類是否能運行一個功能測試,默認為false)
15、<permission>、<uses-permission>、<permission-tree />、<permission-group />區(qū)別~
最常用的當(dāng)屬<uses-permission>,當(dāng)我們需要獲取某個權(quán)限的時候就必須在我們的manifest文件中聲明,此<uses-permission>與<application>同級,具體權(quán)限列表請看此處
通常情況下我們不需要為自己的應(yīng)用程序聲明某個權(quán)限,除非你提供了供其他應(yīng)用程序調(diào)用的代碼或者數(shù)據(jù)。這個時候你才需要使用<permission> 這個標簽。很顯然這個標簽可以讓我們聲明自己的權(quán)限。比如:
<permission android:name="com.teleca.project.MY_SECURITY" . . . />
那么在activity中就可以聲明該自定義權(quán)限了,如:
<application . . .>
??????? <activity android:name="XXX" . . . >
????????????????? android:permission="com.teleca.project.MY_SECURITY"> </activity>
?</application>
當(dāng)然自己聲明的permission也不能隨意的使用,還是需要使用<uses-permission>來聲明你需要該權(quán)限
<permission-group> 就是聲明一個標簽,該標簽代表了一組permissions,而<permission-tree>是為一組permissions聲明了一個namespace。這兩個標簽可以看之前的系列文章。
程序執(zhí)行需要讀取到安全敏感項必需在androidmanifest.xml中聲明相關(guān)權(quán)限請求, 完整列表如下:
1. android.permission.ACCESS_CHECKIN_PROPERTIES
? ? 允許讀寫訪問”properties”表在 checkin數(shù)據(jù)庫中,改值可以修改上傳( Allows read/write access to the “properties” table in the checkin database, to change values that get uploaded)
2. android.permission.ACCESS_COARSE_LOCATION
? ? 允許一個程序訪問CellID或WiFi熱點來獲取粗略的位置(Allows an application to access coarse (e.g., Cell-ID, WiFi) location)
3. android.permission.ACCESS_FINE_LOCATION
? ? 允許一個程序訪問精良位置(如GPS) (Allows an application to access fine (e.g., GPS) location)
4. android.permission.ACCESS_LOCATION_EXTRA_COMMANDS
? ? 允許應(yīng)用程序訪問額外的位置提供命令(Allows an application to access extra location provider commands)
5. android.permission.ACCESS_MOCK_LOCATION
? ? 允許程序創(chuàng)建模擬位置提供用于測試(Allows an application to create mock location providers for testing)
6. android.permission.ACCESS_NETWORK_STATE
? ? 允許程序訪問有關(guān)GSM網(wǎng)絡(luò)信息(Allows applications to access information about networks)
7. android.permission.ACCESS_SURFACE_FLINGER
? ? 允許程序使用SurfaceFlinger底層特性 (Allows an application to use SurfaceFlinger’s low level features)
8. android.permission.ACCESS_WIFI_STATE
? ? 允許程序訪問Wi-Fi網(wǎng)絡(luò)狀態(tài)信息(Allows applications to access information about Wi-Fi networks)
9. android.permission.ADD_SYSTEM_SERVICE
? ? 允許程序發(fā)布系統(tǒng)級服務(wù)(Allows an application to publish system-level services).
10. android.permission.BATTERY_STATS
? ? 允許程序更新手機電池統(tǒng)計信息(Allows an application to update the collected battery statistics)
?
11. android.permission.BLUETOOTH
? ? 允許程序連接到已配對的藍牙設(shè)備(Allows applications to connect to paired bluetooth devices)
12. android.permission.BLUETOOTH_ADMIN
? ? 允許程序發(fā)現(xiàn)和配對藍牙設(shè)備(Allows applications to discover and pair bluetooth devices)
13. android.permission.BRICK
? ? 請求能夠禁用設(shè)備(非常危險)(Required to be able to disable the device (very *erous!).)
14. android.permission.BROADCAST_PACKAGE_REMOVED
? ? 允許程序廣播一個提示消息在一個應(yīng)用程序包已經(jīng)移除后(Allows an application to broadcast a notification that an application package has been removed)
15. android.permission.BROADCAST_STICKY
? ? 允許一個程序廣播常用intents(Allows an application to broadcast sticky intents)
16. android.permission.CALL_PHONE
? ? 允許一個程序初始化一個電話撥號不需通過撥號用戶界面需 要用戶確認 (Allows an application to initiate a phone call without going through the Dialer user interface for the user to confirm the call being placed.)
17. android.permission.CALL_PRIVILEGED
? ? 允許一個程序撥打任何號碼,包含緊急號碼無需通過撥號用戶界面需要用戶確認 (Allows an application to call any phone number, including emergency numbers, without going through the Dialer user interface for the user to confirm the call being placed)
18. android.permission.CAMERA
? ? 請求訪問使用照相設(shè)備(Required to be able to access the camera device. )
19. android.permission.CHANGE_COMPONENT_ENABLED_STATE
? ? 允許一個程序是否改變一個組件或其他的啟用或禁用(Allows an application to change whether an application component (other than its own) is enabled or not. )
20. android.permission.CHANGE_CONFIGURATION
? ? 允許一個程序修改當(dāng)前設(shè)置,如本地化(Allows an application to modify the current configuration, such as locale. )
?
21. android.permission.CHANGE_NETWORK_STATE
? ? 允許程序改變網(wǎng)絡(luò)連接狀態(tài)(Allows applications to change network connectivity state)
22. android.permission.CHANGE_WIFI_STATE
? ? 允許程序改變Wi-Fi連接狀態(tài)(Allows applications to change Wi-Fi connectivity state)
23. android.permission.CLEAR_APP_CACHE
? ? 允許一個程序清楚緩存從所有安裝的程序在設(shè)備中(Allows an application to clear the caches of all installed applications on the device. )
24. android.permission.CLEAR_APP_USER_DATA
? ? 允許一個程序清除用戶設(shè)置(Allows an application to clear user data)
25. android.permission.CONTROL_LOCATION_UPDATES
? ? 允許啟用禁止位置更新提示從無線模塊 (Allows enabling/disabling location update notifications from the radio. )
26. android.permission.DELETE_CACHE_FILES
? ? 允許程序刪除緩存文件(Allows an application to delete cache files)
27. android.permission.DELETE_PACKAGES
? ? 允許一個程序刪除包(Allows an application to delete packages)
28. android.permission.DEVICE_POWER
? ? 允許訪問底層電源管理(Allows low-level access to power management)
29. android.permission.DIAGNOSTIC
? ? 允許程序RW診斷資源(Allows applications to RW to diagnostic resources. )
30. android.permission.DISABLE_KEYGUARD
? ? 允許程序禁用鍵盤鎖(Allows applications to disable the keyguard )
?
31. android.permission.DUMP
? ? 允許程序返回狀態(tài)抓取信息從系統(tǒng)服務(wù)(Allows an application to retrieve state dump information from system services.)
32. android.permission.EXPAND_STATUS_BAR
? ? 允許一個程序擴展收縮在狀態(tài)欄,android開發(fā)網(wǎng)提示應(yīng)該是一個類似Windows Mobile中的托盤程序(Allows an application to expand or collapse the status bar. )
33. android.permission.FACTORY_TEST
? ? 作為一個工廠測試程序,運行在root用戶(Run as a manufacturer test application, running as the root user. )
34. android.permission.FLASHLIGHT
? ? 訪問閃光燈,android開發(fā)網(wǎng)提示HTC Dream不包含閃光燈(Allows access to the flashlight )
35. android.permission.FORCE_BACK
? ? 允許程序強行一個后退操作是否在頂層activities(Allows an application to force a BACK operation on whatever is the top activity. )
36. android.permission.FOTA_UPDATE
? ? 暫時不了解這是做什么使用的,android開發(fā)網(wǎng)分析可能是一個預(yù)留權(quán)限.
37. android.permission.GET_ACCOUNTS
? ? 訪問一個帳戶列表在Accounts Service中(Allows access to the list of accounts in the Accounts Service)
38. android.permission.GET_PACKAGE_SIZE
? ? 允許一個程序獲取任何package占用空間容量(Allows an application to find out the space used by any package. )
39. android.permission.GET_TASKS
? ? 允許一個程序獲取信息有關(guān)當(dāng)前或最近運行的任務(wù), 一個縮略的任務(wù)狀態(tài),是否活動等等(Allows an application to get information about the currently or recently running tasks: a thumbnail representation of the tasks, what activities are running in it, etc.)
40. android.permission.HARDWARE_TEST
? ? 允許訪問硬件(Allows access to hardware peripherals. )
?
41. android.permission.INJECT_EVENTS
? ? 允許一個程序截獲用戶事件如按鍵、觸摸、軌跡球等等到一個時間流,android 開發(fā)網(wǎng)提醒算是hook技術(shù)吧(Allows an application to inject user events (keys, touch, trackball) into the event stream and deliver them to ANY window.)
42. android.permission.INSTALL_PACKAGES
? ? 允許一個程序安裝packages(Allows an application to install packages. )
43. android.permission.INTERNAL_SYSTEM_WINDOW
? ? 允許打開窗口使用系統(tǒng)用戶界面(Allows an application to open windows that are for use by parts of the system user interface. )
44. android.permission.INTERNET
? ? 允許程序打開網(wǎng)絡(luò)套接字(Allows applications to open network sockets)
45. android.permission.MANAGE_APP_TOKENS
? ? 允許程序管理(創(chuàng)建、催后、 z- order默認向z軸推移)程序引用在窗口管理器中(Allows an application to manage (create, destroy, Z-order) application tokens in the window manager. )
46. android.permission.MASTER_CLEAR
目前還沒有明確的解釋,android開發(fā)網(wǎng)分析可能是清除一切數(shù)據(jù),類似硬格機
47. android.permission.MODIFY_AUDIO_SETTINGS
? ? 允許程序修改全局音頻設(shè)置(Allows an application to modify global audio settings)
48. android.permission.MODIFY_PHONE_STATE
? ? 允許修改話機狀態(tài),如電源,人機接口等(Allows modification of the telephony state ? power on, mmi, etc. )
49. android.permission.MOUNT_UNMOUNT_FILESYSTEMS
? ? 允許掛載和反掛載文件系統(tǒng)可移動存儲 (Allows mounting and unmounting file systems for removable storage. )
50. android.permission.PERSISTENT_ACTIVITY
? ? 允許一個程序設(shè)置他的activities顯示 (Allow an application to make its activities persistent. )
?
51. android.permission.PROCESS_OUTGOING_CALLS
? ? 允許程序監(jiān)視、修改有關(guān)播出電話(Allows an application to monitor, modify, or abort outgoing calls)
52. android.permission.READ_CALENDAR
? ? 允許程序讀取用戶日歷數(shù)據(jù)(Allows an application to read the user’s calendar data.)
53. android.permission.READ_CONTACTS
? ? 允許程序讀取用戶聯(lián)系人數(shù)據(jù)(Allows an application to read the user’s contacts data.)
54. android.permission.READ_FRAME_BUFFER
? ? 允許程序屏幕波或和更多常規(guī)的訪問幀緩沖數(shù)據(jù)(Allows an application to take screen shots and more generally get access to the frame buffer data)
55. android.permission.READ_INPUT_STATE
? ? 允許程序返回當(dāng)前按鍵狀態(tài)(Allows an application to retrieve the current state of keys and switches. )
56. android.permission.READ_LOGS
? ? 允許程序讀取底層系統(tǒng)日志文件(Allows an application to read the low-level system log files. )
57. android.permission.READ_OWNER_DATA
? ? 允許程序讀取所有者數(shù)據(jù)(Allows an application to read the owner’s data)
58. android.permission.READ_SMS
? ? 允許程序讀取短信息(Allows an application to read SMS messages.)
59. android.permission.READ_SYNC_SETTINGS
? ? 允許程序讀取同步設(shè)置(Allows applications to read the sync settings)
60. android.permission.READ_SYNC_STATS
? ? 允許程序讀取同步狀態(tài)(Allows applications to read the sync stats)
?
61. android.permission.REBOOT
? ? 請求能夠重新啟動設(shè)備(Required to be able to reboot the device. )
62. android.permission.RECEIVE_BOOT_COMPLETED
? ? 允許一個程序接收到 ACTION_BOOT_COMPLETED廣播在系統(tǒng)完成啟動(Allows an application to receive the ACTION_BOOT_COMPLETED that is broadcast after the system finishes booting. )
63. android.permission.RECEIVE_MMS
? ? 允許一個程序監(jiān)控將收到MMS彩信,記錄或處理(Allows an application to monitor incoming MMS messages, to record or perform processing on them. )
64. android.permission.RECEIVE_SMS
? ? 允許程序監(jiān)控一個將收到短信息,記錄或處理(Allows an application to monitor incoming SMS messages, to record or perform processing on them.)
65. android.permission.RECEIVE_WAP_PUSH
? ? 允許程序監(jiān)控將收到WAP PUSH信息(Allows an application to monitor incoming WAP push messages. )
66. android.permission.RECORD_AUDIO
? ? 允許程序錄制音頻(Allows an application to record audio)
67. android.permission.REORDER_TASKS
? ? 允許程序改變Z軸排列任務(wù)(Allows an application to change the Z-order of tasks)
68. android.permission.RESTART_PACKAGES
? ? 允許程序重新啟動其他程序(Allows an application to restart other applications)
69. android.permission.SEND_SMS
? ? 允許程序發(fā)送SMS短信(Allows an application to send SMS messages)
?
70. android.permission.SET_ACTIVITY_WATCHER
? ? 允許程序監(jiān)控或控制activities已經(jīng)啟動全局系統(tǒng)中Allows an application to watch and control how activities are started globally in the system.
71. android.permission.SET_ALWAYS_FINISH
? ? 允許程序控制是否活動間接完成在處于后臺時Allows an application to control whether activities are immediately finished when put in the background.
72. android.permission.SET_ANIMATION_SCALE
? ? 修改全局信息比例(Modify the global animation scaling factor.)
73. android.permission.SET_DEBUG_APP
? ? 配置一個程序用于調(diào)試(Configure an application for debugging.)
74. android.permission.SET_ORIENTATION
? ? 允許底層訪問設(shè)置屏幕方向和實際旋轉(zhuǎn)(Allows low-level access to setting the orientation(actually rotation) of the screen.)
75. android.permission.SET_PREFERRED_APPLICATIONS
? ? 允許一個程序修改列表參數(shù) PackageManager.addPackageToPreferred() 和PackageManager.removePackageFromPreferred()方法(Allows an application to modify the list of preferred applications with the PackageManager.addPackageToPreferred() and PackageManager.removePackageFromPreferred() methods.)
76. android.permission.SET_PROCESS_FOREGROUND
? ? 允許程序當(dāng)前運行程序強行到前臺(Allows an application to force any currently running process to be in the foreground.)
77. android.permission.SET_PROCESS_LIMIT
? ? 允許設(shè)置最大的運行進程數(shù)量(Allows an application to set the maximum number of (not needed) application processes that can be running. )
78. android.permission.SET_TIME_ZONE
? ? 允許程序設(shè)置時間區(qū)域(Allows applications to set the system time zone)
79. android.permission.SET_WALLPAPER
? ? 允許程序設(shè)置壁紙(Allows applications to set the wallpaper )
80. android.permission.SET_WALLPAPER_HINTS
? ? 允許程序設(shè)置壁紙hits(Allows applications to set the wallpaper hints)
?
81. android.permission.SIGNAL_PERSISTENT_PROCESSES
? ? 允許程序請求發(fā)送信號到所有顯示的進程中 (Allow an application to request that a signal be sent to all persistent processes)
82. android.permission.STATUS_BAR
? ? 允許程序打開、關(guān)閉或禁用狀態(tài)欄及圖標Allows an application to open, close, or disable the status bar and its icons.
83. android.permission.SUBSCRIBED_FEEDS_READ
? ? 允許一個程序訪問訂閱RSS Feed內(nèi)容提供(Allows an application to allow access the subscribed feeds ContentProvider. )
84. android.permission.SUBSCRIBED_FEEDS_WRITE
? ? 系統(tǒng)暫時保留改設(shè)置,android開發(fā)網(wǎng)認為未來版本會加入該功能。
85. android.permission.SYSTEM_ALERT_WINDOW
? ? 允許一個程序打開窗口使用 TYPE_SYSTEM_ALERT,顯示在其他所有程序的頂層(Allows an application to open windows using the type TYPE_SYSTEM_ALERT, shown on top of all other applications. )
86. android.permission.VIBRATE
? ? 允許訪問振動設(shè)備(Allows access to the vibrator)
87. android.permission.WAKE_LOCK
? ? 允許使用PowerManager的 WakeLocks保持進程在休眠時從屏幕消失( Allows using PowerManager WakeLocks to keep processor from sleeping or screen from dimming)
88. android.permission.WRITE_APN_SETTINGS
? ? 允許程序?qū)懭階PI設(shè)置(Allows applications to write the apn settings)
89. android.permission.WRITE_CALENDAR
? ? 允許一個程序?qū)懭氲蛔x取用戶日歷數(shù)據(jù)(Allows an application to write (but not read) the user’s calendar data. )
90. android.permission.WRITE_CONTACTS
? ? 允許程序?qū)懭氲蛔x取用戶聯(lián)系人數(shù)據(jù)(Allows an application to write (but not read) the user’s contacts data. )
91. android.permission.WRITE_GSERVICES
? ? 允許程序修改Google服務(wù)地圖(Allows an application to modify the Google service map. )
92. android.permission.WRITE_OWNER_DATA
? ? 允許一個程序?qū)懭氲蛔x取所有者數(shù)據(jù)(Allows an application to write (but not read) the owner’s data.)
93. android.permission.WRITE_SETTINGS
? ? 允許程序讀取或?qū)懭胂到y(tǒng)設(shè)置(Allows an application to read or write the system settings. )
94. android.permission.WRITE_SMS
? ? 允許程序?qū)懚绦?Allows an application to write SMS messages)
95. android.permission.WRITE_SYNC_SETTINGS
? ? 允許程序?qū)懭胪皆O(shè)置(Allows applications to write the sync settings)
android平臺上的權(quán)限許可分得很細,如果軟件無法正常執(zhí)行時看看是不是缺少相關(guān)的permission聲明,最終我們還需要使用 android sign tools簽名生成的apk文件。
總結(jié)
以上是生活随笔為你收集整理的Android之AndroidManifest.xml文件解析和权限集合的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android之如何成为Android高
- 下一篇: Android之图片缓存管理