Android Package and Manifest File

Android应用配置详解
本文详细介绍了Android应用程序的基本组成,包括Android项目的概念、AndroidManifest.xml文件的结构及其各个元素的作用,如定义应用程序组件、指定权限需求及行为等。
The Android project, sometimes also referred to as an Android package, is a collection ofJava packages. Different Android packages can have the same Java package names, whereasthe Android package name must be unique across all applications installed on theAndroid device.

For the OS to access them, each application must declare its available components in asingle AndroidManifest XML file. In addition, this file contains the required permissionsand behavior for the application to run. Listing 2.5 shows what it looks like for the “Creatinga Project and an Activity” recipe.


Listing AndroidManifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.cookbook.simple_activity"
android:versionCode="1"
android:versionName="1.0">

<application android:icon="@drawable/icon"

android:label="@string/app_name">
<activity android:name=".SimpleActivity"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="3" />
</manifest>
The first line is required and standard across all XML files in Android to specify the
encoding.The manifest element defines the Android package name and version.The
versionCode is an integer that can be evaluated in programs to determine the upgrade or
downgrade relationship.The versionName represents a human readable format that can
have major and minor revisions declared.
The application element defines the icon and label the user sees from the Android
device menu.The label is a string and should be short enough to display under the icon
on a user’s device. Generally the name can be up to two words of ten characters each
without being cut off.
The activity element defines the main activity that is launched when the application
is started and the name shown in the title bar when the activity is active. Here, the Java
package name needs to be specified, which is com.cookbook.simple_activity.
SimpleActivity in this case. Because the Java package name is usually the same as
the Android package name, the shorthand notation is often used: .SimpleActivity.
However, it is best to remember that the Android package and Java package are
distinct.
The intent-filter element informs the Android system of the capabilities of the
component. It can have multiple action, category, or data elements for this purpose.This is
seen as it is utilized in different recipes.
The uses-sdk element defines the application programming interface (API) level
required to run this application. In general, the API level is specified as follows:
<uses-sdk android:minSdkVersion="integer"
android:targetSdkVersion="integer"
android:maxSdkVersion="integer" />
Because the Android OS is constructed to be forward compatible, the maxSdkVersion is
highly discouraged and not even adhered on devices with Android 2.0.1 or later. Specifying
the targetSdkVersion is not required, but allows devices of the same SDK version to
disable compatibility settings that might speed up operation.The minSdkVersion should
always be specified to ensure the application does not crash when run on a platform that does not support the required features in the application.Always choose the lowest API

level possible when specifying this.
The AndroidManifest can also contain permission settings needed to run the application.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值