版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u011391629/article/details/82348121
主要参考Android Developer,目前刚开始Study,后续in-depth study后会更新。
App Manifest Overview
每个应用的根目录中都必须包含一个 AndroidManifest.xml 文件(文件名必须是这个)。 AndroidManifest.xml 向 Android 系统提供该APP的必要信息,比如Android build tools,Android operating system,Google Play。
AndroidManifest提供的信息:
- The app’s package name
- The components of the app
- The permissions that the app needs in order to access protected parts of the system or other apps
- The hardware and software features the app requires
File features
- Package name and Application ID
- App components
- Permissions
- Device compatibility
Package name and Application ID
For example:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp"
android:versionCode="1"
android:versionName="1.0" >
...
</manifest>
App components
<activity>
for each subclass ofActivity
<service>
for each subclass ofService
<receiver>
for each subclass ofBroadcastReceiver
<provider>
for each subclass ofContentProvider
For example:
<manifest package="com.example.myapp" ... >
<application ... >
<activity android:name=".MainActivity" ... >
...
</activity>
</application>
</manifest>
- Intent filters
- Icons and labels
Permissions
在使用手机的时候,第一次install一个app的时候,会让你选择是否允许访问图片,是否开启定位等等。APP对于一些数据或者某些系统功能需要先请求权限。在AndroidManifest中,每一个权限都具有唯一标签。
For example:
<manifest ... >
<uses-permission android:name="android.permission.SEND_SMS"/>
...
</manifest>
Device compatibility
<uses-feature>
<uses-sdk>
For example:
<manifest ... >
<uses-feature android:name="android.hardware.sensor.compass"
android:required="true" />
...
</manifest>
File conventions
- Elements(
<manifest>
<application>
…) - Attributes(
android: prefix = xxxx
) - Multiple values
- Resource values(Format:
"@[package:]type/name"
) - String values
For example
以Android Pie(9.0)的CarSettings为例(full path:/packages/apps/Car/Settings/AndroidManifest.xml)。
<?xml version="1.0" encoding="utf-8"?>
<!--
Copyright (C) 2017 The Android Open Source Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
-->
<!--
Package name:包名com.android.car.settings
sharedUserId:数据权限
versionCode:APP版本,1.2.3...
versionName:APP版本,给用户看的,1.0,1.1...2.0,2.1...等等
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.android.car.settings"
android:sharedUserId="android.uid.system"
android:versionCode="1"
android:versionName="1.0">
<!--
minSdkVersion: CarSettings支持的最小版本(API Level)为24,对应的Platform Version为Android 7.0
targetSdkVersion: CarSettings支持的目标版本为(API Level)24,对应的Platform Version为Android 7.0
同理的还有maxSdkVersion,API Level与Platform Version的对应关系可参考链接:
https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels
-->
<uses-sdk
android:minSdkVersion="24"
android:targetSdkVersion="24"/>
<!--
声明CarSettings所需的权限:WIFI/BLUETOOTH/USERS/TIME...
Android系统提供了100多个权限,可通过这个链接查看:
https://developer.android.com/reference/android/Manifest.permission
-->
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.BACKUP"/>
<uses-permission android:name="android.permission.BLUETOOTH"/>
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"/>
<uses-permission android:name="android.permission.CLEAR_APP_USER_DATA"/>
<uses-permission android:name="android.permission.DELETE_CACHE_FILES"/>
<uses-permission android:name="android.permission.DUMP"/>
<uses-permission android:name="android.permission.FORCE_STOP_PACKAGES"/>
<uses-permission android:name="android.permission.GET_ACCOUNTS_PRIVILEGED"/>
<uses-permission android:name="android.permission.GET_PACKAGE_SIZE"/>
<uses-permission android:name="android.permission.INJECT_EVENTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.MANAGE_ACCOUNTS"/>
<uses-permission android:name="android.permission.MANAGE_USERS"/>
<uses-permission android:name="android.permission.MASTER_CLEAR" />
<uses-permission android:name="android.permission.NETWORK_SETTINGS" />
<uses-permission android:name="android.permission.OVERRIDE_WIFI_CONFIG"/>
<uses-permission android:name="android.permission.READ_CONTACTS"/>
<uses-permission android:name="android.permission.REBOOT"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.SET_PREFERRED_APPLICATIONS"/>
<uses-permission android:name="android.permission.SET_TIME"/>
<uses-permission android:name="android.permission.SET_TIME_ZONE"/>
<uses-permission android:name="android.permission.START_FOREGROUND"/>
<uses-permission android:name="android.permission.WRITE_MEDIA_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_SETTINGS"/>
<uses-permission android:name="android.permission.WRITE_SECURE_SETTINGS"/>
<!--
icon:图标,path:/drawable/ic_launcher_settings
theme:主题,定义了一个默认的主题风格给所有的activity
label:序列列表,字符串资源,path:string/settings_label
supportsRtl:支持RTL(Right to Left)的布局
-->
<application
android:icon="@drawable/ic_launcher_settings"
android:theme="@style/CarSettingTheme"
android:label="@string/settings_label"
android:supportsRtl="true">
<!--
name/label:与application中的相同
launchMode:Activity加载模式(standard/singleTop/singleTask/singleInstance)
windowSoftInputMode: activity主窗口与软键盘的交互模式
exported: 是否支持其它应用调用当前组件(有intent-filter默认为true,否则为false)
-->
<activity
android:name=".common.CarSettingActivity"
android:label="@string/settings_label"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan"
android:exported="true">
<!-- Set priority high enough to trump the phone setting app -->
<!-- TODO: once phone setting is removed from car system image, set priority to 1 -->
<!--
action: 只有android:name这个属性
category:只有android:name这个属性
具体的action/category属性在Android Developer有介绍:
https://developer.android.google.cn/reference/android/content/Intent
intent-filter包含action/category/data
android.intent.action.MAIN表示此activity是作为应用程序的入口
-->
<intent-filter android:priority="10">
<action android:name="android.intent.action.MAIN" />
<action android:name="android.settings.SETTINGS" />
<category android:name="android.intent.category.DEFAULT"/>
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<meta-data android:name="distractionOptimized" android:value="true"/>
</activity>
<activity android:name=".bluetooth.BluetoothPairingDialog"
android:excludeFromRecents="true"
android:windowSoftInputMode="stateVisible|adjustResize"
android:theme="@*android:style/Theme.DeviceDefault.Settings.Dialog.NoActionBar">
</activity>
<activity android:name=".accounts.AddAccountActivity"
android:theme="@android:style/Theme.Translucent.NoTitleBar"
android:configChanges="orientation|keyboardHidden|screenSize">
<intent-filter>
<action android:name="android.car.settings.ADD_ACCOUNT_SETTINGS" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity android:name=".security.SettingsScreenLockActivity"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustResize">
</activity>
<activity android:name=".security.SetupWizardScreenLockActivity"
android:theme="@style/Theme.Car.Shared.SetupWizard.NoActionBar"
android:configChanges="orientation|keyboardHidden|screenSize"
android:windowSoftInputMode="adjustResize">
<intent-filter>
<action android:name="android.car.settings.SETUP_WIZARD_SCREEN_LOCK_ACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service android:name=".bluetooth.BluetoothPairingService" />
<receiver android:name=".bluetooth.BluetoothPairingRequest">
<intent-filter>
<action android:name="android.bluetooth.device.action.PAIRING_REQUEST" />
</intent-filter>
</receiver>
</application>
</manifest>