版權(quán)說明:本文檔由用戶提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請進行舉報或認領
文檔簡介
1、android api級別當你開發(fā)你的android應用程序時,了解該平臺api變更管理的基本方法和概念是很有幫助的。同樣的,知道api級別標識以及該標識如何保障你的應用與實際硬件設備相兼容對于開發(fā)及后續(xù)的發(fā)布、維護都是有益的。本節(jié)內(nèi)容告訴你api級別的知識,以及它如何影響你開發(fā)和使用的應用。關(guān)于如何使用“以api級別進行過濾”來使用api參考手冊,從本文末尾的文檔過濾(filtering the documentation)中可以得到更多信息。api級別是什么?api級別是一個整數(shù)值,它唯一標識了一個具體版本的android平臺,及其框架的api的版本。android平臺提供了一套框架api
2、,使得應用程序可以與系統(tǒng)底層進行交互。該框架api由以下模塊組成: 一組核心的包和類 清單(manifest)文件的xml元素和屬性聲明 資源文件的xml元素和屬性聲明及訪問形式 各類意圖(intents) 應用程序可以請求的各類授權(quán),以及系統(tǒng)中包含的授權(quán)執(zhí)行每個android平臺的后續(xù)版本會包括它提供的更新的android應用程序框架的api。該框架的api的更新設計,使高版本的api與早期版本兼容。也就是說,在新版本api中大多數(shù)都是新增功能,和引進新的或替代的功能。作為api的部分升級,老的替換的部分已過時,但不會從新版本中刪除,使得已有的應用程序仍然可以使用它們。在極少數(shù)情況下,舊版本
3、api的部分可能被修改或刪除,通常這種變化是為了保障api的穩(wěn)定性及應用程序或系統(tǒng)的安全。所有其他早期版本的api將不做修改的保留。一個android平臺提供的框架api,被指定一個整數(shù)標識符,稱為“api級別”。每一個版本的android平臺只支持有一個api級別,雖然該支持是隱含地包括了所有早期的api級別(一直到api級別1級)。android平臺的最初版本提供的框架api級別是1級,隨后的版本依次遞增。下表說明了具體平臺版本和支持的api級別的對應關(guān)系。平臺版本api級別android 3.011android 2.3.310android 2.39android 2.28androi
4、d 2.17android 2.0.16android 2.05android 1.64android 1.53android 1.12android 1.01在android中使用api級別api級別標識為保證用戶和應用程序開發(fā)者的最佳體驗,起了關(guān)鍵作用: 它讓android平臺可以描述它支持的框架api的最高版本 它讓應用程序可以描述它需要的框架api版本 它使得系統(tǒng)可以在硬件設備上安裝應用程序時能夠檢查版本是否匹配,使得版本不兼容的應用程序不會被錯誤安裝在設備之上.每個版本的android平臺都在其內(nèi)部存儲了自己的api級別標識。應用程序可以用框架api提供的清單文件元素來描述該應用程序
5、可以運行的最小和最大api級別,以及應用程序開發(fā)者設計期望運行的平臺版本。三種屬性分別描述如下: android:minsdkversion指明該應用程序可以運行的api最低版本。默認是“1”。 android:targetsdkversion指明該應用程序設計時期望運行的目標api版本。在某些情況下,這允許應用程序使用目標api級別下定義的清單元素或行為,而不是只限于使用最低api級別定義的內(nèi)容。 android:maxsdkversion指明該應用程序可以運行的最高api級別。重要聲明:使用該屬性之前請閱讀文檔。比如,要指明一個應用程序能夠運行的最低api級別,應當在該應用程序的清單文件的
6、元素中加入android:minsdkversion屬性。android:minsdkversion的值是一個正整數(shù),對應的是該應用程序能夠運行的最低平臺的api級別標識。用戶嘗試安裝一個應用程序,或者在系統(tǒng)升級后重驗證應用程序的時候,android系統(tǒng)首先會檢查應用程序的清單文件中的屬性,將其與系統(tǒng)內(nèi)部api級別對比。系統(tǒng)只有在滿足下列情況時才允許進行應用程序安裝: 如果聲明了android:minsdkversion屬性,其屬性值必須小于或等于該系統(tǒng)的api級別對應的整數(shù)值。如果未聲明,系統(tǒng)會默認該應用程序運行需要的最低api級別是1。 如果聲明了android:maxsdkversion
7、屬性,其屬性值必須等于或大于該系統(tǒng)的api級對應的整數(shù)值。如果未聲明,系統(tǒng)會默認該應用程序沒有最高api級別限制。請通過閱讀文檔以獲得系統(tǒng)如何處理該屬性的更多信息。應用程序清單文件中聲明該屬性后,元素看起來應類似于下面的例子: .這樣做的主要原因是,應用程序會通過android:minisdkversion聲明的api級別來告知系統(tǒng)該應用程序使用的api是指定引入的api級別。假如沒有這種屬性聲明,一個應用程序如果因為某些不知名的原因被安裝在低級別api系統(tǒng)之上,那么該應用程序會在運行時因為嘗試訪問不存在的api而崩潰。為此,android系統(tǒng)通過不允許應用程序被安裝在不滿足其最低api級別要
8、求的目標硬件上來防止此類結(jié)果發(fā)生。例如,android.appwidget類包是在api級別3中開始引入的。如果一個應用程序使用了這個api,就必須通過指明android:minsdkversion屬性為3來聲明運行的最低要求。于是,該應用程序就可以在android 1.5(api級別3級)、android 1.6 (api級別4級)等平臺上安裝,但是在android 1.1 (api級別2級)和android 1.0平臺(api級別1級)上卻是無法安裝的。欲知關(guān)于如何聲明應用程序api級別需求的更多信息,請閱讀文檔中關(guān)于清單文件的章節(jié)。開發(fā)者需要考慮的內(nèi)容本節(jié)屬于應用程序開發(fā)者需要了解的內(nèi)容
9、。應用程序的向前兼容性android應用程序一般向前兼容于android平臺的新版本。這是因為幾乎所有的框架api變更都是添加性質(zhì)的,一個以某種版本的api開發(fā)的應用程序是向前兼容與后續(xù)android系統(tǒng)及高版本api。應用程序應當可以運行于高版本的平臺,除非使用了未來因某種原因移除的api。向前兼容性的特性如此重要,是因為很多的android驅(qū)動的設備能夠使用ota遠程下載技術(shù)進行系統(tǒng)更新。用戶開始時能夠很好的安裝和使用你開發(fā)的應用程序,后來進行了ota升級到新版本的android平臺。一旦升級完畢,你的應用程序?qū)⑦\行在一個新的版本環(huán)境下,而這個環(huán)境應當包含了你的應用程序所需的api和系統(tǒng)功
10、能。某些情況下,api背后的變化,例如系統(tǒng)底層的變化,可能會影響到你的應用程序運行在新的環(huán)境下。為此,作為應用程序開發(fā)人員,應當了解應用程序在不同系統(tǒng)環(huán)境下將會有如何的外觀和行為。android sdk包含了多個平臺版本,開發(fā)人員可以下載下來,用于測試自己的應用程序在不同版本下的運行情況。每個版本的平臺都提供了兼容的系統(tǒng)鏡像,你可以將應用程序運行在對應的android虛擬設備(模擬器)上進行測試。應用程序的向后兼容性android應用程序不一定向后兼容于那些比這些應用程序開發(fā)環(huán)境低的平臺環(huán)境。android平臺的每個新版本包含了新的框架api,例如新的平臺功能,或者替代部分已有的api。應用程
11、序在新平臺上可以訪問這些新的api,就像之前提到的,在后續(xù)更新的版本中,這些新功能api也是可以繼續(xù)使用。相反的,因為早期版本的平臺不會包含新的api功能,使用了新api的應用程序在那些舊平臺上是無法運行的。雖然一個android平臺設備不太可能降級到以前的版本,但是需要了解的是:實際生活中可能會有很多設備運行的是較舊的平臺版本。即使在設備接收到ota遠程下載升級,有些人仍然可能會滯后甚至可能不會收到更新。平臺版本和api級別的選擇當你開發(fā)應用程序時,你需要選擇一個平臺用于編譯該應用程序。通常,你應該在你的應用程序可以支持的最低版本的平臺上進行編譯。你可以通過尋找最低的可以支持你的應用程序編譯
12、的平臺方式來決定你將會支持的最低平臺版本。一旦你確定了支持的最低版本后,你就可以創(chuàng)建對應版本的avd模擬器來全面測試你的應用程序。你需要注意的是不要忘記在應用程序清單文件中申明android:minsdkversion屬性,并賦上正確的api級別標識。聲明最低api級別如果你開發(fā)的應用程序使用了最新平臺上引入的api或平臺特性,你就需要將android:minsdkversion屬性賦最新平臺的api級別標識。這將保證用戶只能在他們的設備與你的應用程序平臺版本兼容情況下安裝。反過來說,這樣能夠保證你的應用程序在他們的設備上表現(xiàn)正常。如果你用了最新的api或平臺特性,但是沒有申明android:
13、minsdkversion屬性,那么你的應用程序在最新平臺上運行是沒有穩(wěn)定,但是在早期版本的平臺上是會出錯的。在后一種情況,應用程序在嘗試訪問舊平臺上不存在的api時會崩潰。針對高版本的api級別測試編譯完你的應用程序,你應當在支持的最低版本平臺上詳細測試應用程序的表現(xiàn)??梢酝ㄟ^創(chuàng)建對應平臺的avd模擬器進行測試。此外,要保證向前兼容性,你應當在你的應用程序可能運行的更高平臺版本上進行運行和測試。android sdk包含了多個平臺版本供開發(fā)者使用,其中包括了最新的版本,并且提供了升級工具使得開發(fā)者可以獲取其他的版本。要使用升級工具,可以通過android命令行方式,該工具位于/tools路徑
14、下。你可以用敲入android指令運行該升級工具,而不用指定任何參數(shù)。你也可以簡單地通過雙擊windows下的android.bat或os x/linux下的android文件來啟動升級工具。在adt工具界面,你可以通過菜單的windowandroid sdk and avd manager來訪問升級工具。要想將你的應用程序在不同平臺版本的模擬器上運行,需要創(chuàng)建對應的avd設備。關(guān)于avd的更多信息,請參見creating and managing virtual devices。如果你用物理設備進行測試,確保清楚運行的具體平臺版本。通過本文開始部分的映射表格可以知道平臺版本對應的api級別標
15、識。使用臨時的api級別某些情況下,有可能會發(fā)布“早期預覽(early look)”版的android平臺sdk。在此平臺版本上開發(fā)使用的api將不會是最終發(fā)布版,平臺的api級別標識數(shù)字就不會指定。你必須在程序清單文件中使用臨時的api級別進行標識,以便建立對應的平臺應用。臨時api級別不是一個整數(shù),而是一個表示未發(fā)布的平臺版本的字符串代號。“早期預覽”版本的api級別在發(fā)布說明中會申明,該代號是大小寫敏感的。臨時api級別標識的用途是保護開發(fā)者和設備使用者免于無意中發(fā)布或安裝在“早期預覽”平臺版本上開發(fā)的應用程序,這些應用程序可能在最終的發(fā)布系統(tǒng)上運行不穩(wěn)定。臨時api級別標識僅僅在使用“
16、早期預覽”版本的sdk下有效,并且只能運行應用程序于模擬器之中。實際的android設備上是無法安裝使用臨時api級別標識的應用程序的。在最終版本平臺發(fā)布后,你必須將程序清單文件中用到的臨時api級別標識替換成最終平臺的實際api級別整數(shù)值。通過api級別進行文檔內(nèi)容過濾android開發(fā)者站點上的參考文檔的每個頁面的右上方提供了“filter by api level”控件。你可以用這個控件來僅僅顯示你應用程序相關(guān)的那部分api文檔,可以通過應用程序清單文件中的android:minsdkversion屬性值進行過濾。要使用過濾功能,可以通過頁面搜索框下面的選擇框來啟用過濾功能。比如設定“f
17、ilter by api level”控件內(nèi)容與你應用程序申明的相同。注意:在選定級別之后引入的心api會以灰色顯示,并且內(nèi)容被隱藏,因為你的應用程序是無法訪問這些新功能。api級別過濾方法不會提供每個api級別中新添加的功能視圖,僅僅展現(xiàn)對應api級別的整個內(nèi)容,其中去除了后續(xù)新版本中的內(nèi)容。如果你不想過濾api文檔了,只需要關(guān)閉該選擇框的特性。api級別過濾默認是關(guān)閉的,因此你可以看到整個框架api的全貌,而不管具體的api級別。還要注意的是個別的api元素申明了該api參考文檔在哪一級引入的。這通過在每個文檔頁面正文部分的右上角的“since ”進行聲明該包和類的引入信息。類成員的api
18、級別在其詳細描述文件頭部的右邊進行描述。android api levelsas you develop your application on android, its useful to understand the platforms general approach to api change management. its also important to understand the api level identifier and the role it plays in ensuring your applications compatibility with devices
19、 on which it may be installed.the sections below provide information about api level and how it affects your applications.for information about how to use the filter by api level control available in the api reference documentation, seefiltering the documentationat the end of this document.what is a
20、pi level?api level is an integer value that uniquely identifies the framework api revision offered by a version of the android platform.the android platform provides a framework api that applications can use to interact with the underlying android system. the framework api consists of: a core set of
21、 packages and classes a set of xml elements and attributes for declaring a manifest file a set of xml elements and attributes for declaring and accessing resources a set of intents a set of permissions that applications can request, as well as permission enforcements included in the systemeach succe
22、ssive version of the android platform can include updates to the android application framework api that it delivers.updates to the framework api are designed so that the new api remains compatible with earlier versions of the api. that is, most changes in the api are additive and introduce new or re
23、placement functionality. as parts of the api are upgraded, the older replaced parts are deprecated but are not removed, so that existing applications can still use them. in a very small number of cases, parts of the api may be modified or removed, although typically such changes are only needed to e
24、nsure api robustness and application or system security. all other api parts from earlier revisions are carried forward without modification.the framework api that an android platform delivers is specified using an integer identifier called api level. each android platform version supports exactly o
25、ne api level, although support is implicit for all earlier api levels (down to api level 1). the initial release of the android platform provided api level 1 and subsequent releases have incremented the api level.the following table specifies the api level supported by each version of the android pl
26、atform.platform versionapi levelandroid 3.011android 2.3.310android 2.39android 2.28android 2.17android 2.0.16android 2.05android 1.64android 1.53android 1.12android 1.01uses of api level in androidthe api level identifier serves a key role in ensuring the best possible experience for users and appl
27、ication developers: it lets the android platform describe the maximum framework api revision that it supports it lets applications describe the framework api revision that they require it lets the system negotiate the installation of applications on the users device, such that version-incompatible a
28、pplications are not installed.each android platform version stores its api level identifier internally, in the android system itself.applications can use a manifest element provided by the framework api to describe the minimum and maximum api levels under which they are able to run, as well as the p
29、referred api level that they are designed to support. the element offers three key attributes: android:minsdkversion specifies the minimum api level on which the application is able to run. the default value is 1. android:targetsdkversion specifies the api level on which the application is designed
30、to run. in some cases, this allows the application to use manifest elements or behaviors defined in the target api level, rather than being restricted to using only those defined for the minimum api level. android:maxsdkversion specifies the maximum api level on which the application is able to run.
31、important:please read thedocumentation before using this attribute.for example, to specify the minimum system api level that an application requires in order to run, the application would include in its manifest aelement with aandroid:minsdkversionattribute. the value ofandroid:minsdkversionwould be
32、 the integer corresponding to the api level of the earliest version of the android platform under which the application can run.when the user attempts to install an application, or when revalidating an appplication after a system update, the android system first checks theattributes in the applicati
33、ons manifest and compares the values against its own internal api level. the system allows the installation to begin only if these conditions are met: if aandroid:minsdkversionattribute is declared, its value must be less than or equal to the systems api level integer. if not declared, the system as
34、sumes that the application requires api level 1. if aandroid:maxsdkversionattribute is declared, its value must be equal to or greater than the systems api level integer. if not declared, the system assumes that the application has no maximum api level. please read thedocumentation for more informat
35、ion about how the system handles this attribute.when declared in an applications manifest, aelement might look like this: .the principal reason that an application would declare an api level inandroid:minsdkversionis to tell the android system that it is using apis that wereintroducedin the api leve
36、l specified. if the application were to be somehow installed on a platform with a lower api level, then it would crash at run-time when it tried to access apis that dont exist. the system prevents such an outcome by not allowing the application to be installed if the lowest api level it requires is
37、higher than that of the platform version on the target device.for example, theandroid.appwidgetpackage was introduced with api level 3. if an application uses that api, it must declare aandroid:minsdkversionattribute with a value of 3. the application will then be installable on platforms such as an
38、droid 1.5 (api level 3) and android 1.6 (api level 4), but not on the android 1.1 (api level 2) and android 1.0 platforms (api level 1).for more information about how to specify an applications api level requirements, see thesection of the manifest file documentation.development considerationsthe se
39、ctions below provide information related to api level that you should consider when developing your application.application forward compatibilityandroid applications are generally forward-compatible with new versions of the android platform.because almost all changes to the framework api are additiv
40、e, an android application developed using any given version of the api (as specified by its api level) is forward-compatible with later versions of the android platform and higher api levels. the application should be able to run on all later versions of the android platform, except in isolated case
41、s where the application uses a part of the api that is later removed for some reason.forward compatibility is important because many android-powered devices receive over-the-air (ota) system updates. the user may install your application and use it successfully, then later receive an ota update to a
42、 new version of the android platform. once the update is installed, your application will run in a new run-time version of the environment, but one that has the api and system capabilities that your application depends on.in some cases, changesbelowthe api, such those in the underlying system itself
43、, may affect your application when it is run in the new environment. for that reason its important for you, as the application developer, to understand how the application will look and behave in each system environment. to help you test your application on various versions of the android platform,
44、the android sdk includes multiple platforms that you can download. each platform includes a compatible system image that you can run in an avd, to test your application.application backward compatibilityandroid applications are not necessarily backward compatible with versions of the android platfor
45、m older than the version against which they were compiled.each new version of the android platform can include new framework apis, such as those that give applications access to new platform capabilities or replace existing api parts. the new apis are accessible to applications when running on the n
46、ew platform and, as mentioned above, also when running on later versions of the platform, as specified by api level. conversely, because earlier versions of the platform do not include the new apis, applications that use the new apis are unable to run on those platforms.although its unlikely that an
47、 android-powered device would be downgraded to a previous version of the platform, its important to realize that there are likely to be many devices in the field that run earlier versions of the platform. even among devices that receive ota updates, some might lag and might not receive an update for
48、 a significant amount of time.selecting a platform version and api levelwhen you are developing your application, you will need to choose the platform version against which you will compile the application. in general, you should compile your application against the lowest possible version of the pl
49、atform that your application can support.you can determine the lowest possible platform version by compiling the application against successively lower build targets. after you determine the lowest version, you should create an avd using the corresponding platform version (and api level) and fully t
50、est your application. make sure to declare aandroid:minsdkversionattribute in the applications manifest and set its value to the api level of the platform version.declaring a minimum api levelif you build an application that uses apis or system features introduced in the latest platform version, you
51、 should set theandroid:minsdkversionattribute to the api level of the latest platform version. this ensures that users will only be able to install your application if their devices are running a compatible version of the android platform. in turn, this ensures that your application can function pro
52、perly on their devices.if your application uses apis introduced in the latest platform version but doesnotdeclare aandroid:minsdkversionattribute, then it will run properly on devices running the latest version of the platform, butnoton devices running earlier versions of the platform. in the latter
53、 case, the application will crash at runtime when it tries to use apis that dont exist on the earlier versions.testing against higher api levelsafter compiling your application, you should make sure to test it on the platform specified in the applicationsandroid:minsdkversionattribute. to do so, cre
54、ate an avd that uses the platform version required by your application. additionally, to ensure forward-compatibility, you should run and test the application on all platforms that use a higher api level than that used by your application.the android sdk includes multiple platform versions that you
55、can use, including the latest version, and provides an updater tool that you can use to download other platform versions as necessary.to access the updater, use theandroidcommand-line tool, located in the /tools directory. you can launch the updater by using theandroidcommand without specifying any
56、options. you can also simply double-click the android.bat (windows) or android (os x/linux) file. in adt, you can also access the updater by selecting windowandroid sdk and avd manager.to run your application against different platform versions in the emulator, create an avd for each platform versio
57、n that you want to test. for more information about avds, seecreating and managing virtual devices. if you are using a physical device for testing, ensure that you know the api level of the android platform it runs. see the table at the top of this document for a list of platform versions and their api levels.using a provisional api levelin some cases, an early look android sdk platform may be available. to let you begin
溫馨提示
- 1. 本站所有資源如無特殊說明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請下載最新的WinRAR軟件解壓。
- 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶所有。
- 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁內(nèi)容里面會有圖紙預覽,若沒有圖紙預覽就沒有圖紙。
- 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
- 5. 人人文庫網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護處理,對用戶上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對任何下載內(nèi)容負責。
- 6. 下載文件中如有侵權(quán)或不適當內(nèi)容,請與我們聯(lián)系,我們立即糾正。
- 7. 本站不保證下載資源的準確性、安全性和完整性, 同時也不承擔用戶因使用這些下載資源對自己和他人造成任何形式的傷害或損失。
最新文檔
- 廣東水利電力職業(yè)技術(shù)學院《建筑學前沿及研究方法》2023-2024學年第一學期期末試卷
- 廣東汕頭幼兒師范高等??茖W?!吨袊鴳蚯费芯俊?023-2024學年第一學期期末試卷
- 廣東茂名農(nóng)林科技職業(yè)學院《歷史學課程教學論》2023-2024學年第一學期期末試卷
- 【優(yōu)化探究】2022屆高三物理一輪復習知能檢測:7-1電場力的性質(zhì)-
- 【全程復習方略】2020-2021學年高中數(shù)學(人教A版選修2-2)課時作業(yè)-2.2.1.2-分析法
- 永州市2025屆高三高考第二次模擬考試(二模)地理試卷
- 2025年人教版八年級數(shù)學寒假預習 第08講 平行四邊形的判定(1個知識點+6大考點舉一反三+過關(guān)測試)
- 《產(chǎn)品知識講解》課件
- 河南省周口市第三初級中學2024-2025學年七年級上學期期末測試英語試卷(含答案無聽力部分)
- 云南省紅河州彌勒二中2021屆高三上學期期中考試物理試卷
- DBJ43-T 315-2016 現(xiàn)澆混凝土保溫免拆模板復合體系應用技術(shù)規(guī)程
- 自然資源價格評估通則 TD/T 1061-2021
- 社區(qū)居家養(yǎng)老食堂方案策劃書(2篇)
- 2024年肺結(jié)節(jié)病的診斷與鑒別診斷講座課件
- 2023-2024學年浙江省寧波市余姚市九年級(上)期末英語試卷
- 健康狀況與風險評估智慧樹知到期末考試答案章節(jié)答案2024年上海健康醫(yī)學院
- 《金融風險管理》期末復習試題及答案
- DZ/T 0462.4-2023 礦產(chǎn)資源“三率”指標要求 第4部分:銅等12種有色金屬礦產(chǎn)(正式版)
- 熱帶園林樹木學智慧樹知到期末考試答案章節(jié)答案2024年海南大學
- 《無機及分析化學》期末考試試卷附答案
- 2024年藥品集中采購合同范本(二篇)
評論
0/150
提交評論