当前位置: 首页 > news >正文

Android开发——初步了解AndroidManifest.xml

Android开发——初步了解AndroidManifest.xml

AndroidManifest.xml 是 Android 应用的清单文件,包含了应用的包名、组件声明、权限声明、API 版本信息等。它是 Android 应用的“说明书”,系统通过它了解应用的结构和行为。咱们的AndroidManifest文件实际上就相当于一份声明式的配置文件了


AndroidManifest.xml 的主要功能

  1. 声明应用的包名
    包名是应用的唯一标识符,用于在系统中区分不同的应用。

    <manifest xmlns:android="http://schemas.android.com/apk/res/android"package="com.example.myapp">
    
  2. 声明应用组件
    包括 ActivityServiceBroadcastReceiverContentProvider。每个组件都需要在清单文件中进行声明。一般而言,我们不会自己重新写这个文件,会让Android Studio自动的修改这个文件

    <applicationandroid:icon="@drawable/ic_launcher"android:label="@string/app_name"><activity android:name=".MainActivity"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity>
    </application>
    
  3. 声明权限
    使用 <uses-permission> 声明应用需要的权限,例如访问网络、读取联系人等。

    <uses-permission android:name="android.permission.INTERNET" />
    
  4. 声明应用的最小 SDK 版本
    使用 <uses-sdk> 声明应用支持的最低和目标 SDK 版本。

    <uses-sdkandroid:minSdkVersion="16"android:targetSdkVersion="30" />
    
  5. 声明应用的特性和功能
    使用 <uses-feature> 声明应用所需的硬件特性,例如摄像头、蓝牙等。

    <uses-feature android:name="android.hardware.camera" />
    

例子:我写的一个迷你demo的AndroidManifest文件

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><applicationandroid:allowBackup="true"android:dataExtractionRules="@xml/data_extraction_rules"android:fullBackupContent="@xml/backup_rules"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.ActivityAction"><activityandroid:name=".SecondActivity"android:exported="false"android:label="@string/title_activity_second"android:theme="@style/Theme.ActivityAction" /><activityandroid:name=".FirstActivity"android:exported="true"android:label="@string/title_activity_first"android:theme="@style/Theme.ActivityAction"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

您提供的 AndroidManifest.xml 文件配置了两个 Activity,并使用了多个与数据备份和安全性相关的属性。以下是对该文件的详细分析:


📁 AndroidManifest.xml 文件结构

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"xmlns:tools="http://schemas.android.com/tools"><applicationandroid:allowBackup="true"android:dataExtractionRules="@xml/data_extraction_rules"android:fullBackupContent="@xml/backup_rules"android:icon="@mipmap/ic_launcher"android:label="@string/app_name"android:roundIcon="@mipmap/ic_launcher_round"android:supportsRtl="true"android:theme="@style/Theme.ActivityAction"><activityandroid:name=".SecondActivity"android:exported="false"android:label="@string/title_activity_second"android:theme="@style/Theme.ActivityAction" /><activityandroid:name=".FirstActivity"android:exported="true"android:label="@string/title_activity_first"android:theme="@style/Theme.ActivityAction"><intent-filter><action android:name="android.intent.action.MAIN" /><category android:name="android.intent.category.LAUNCHER" /></intent-filter></activity></application></manifest>

🧩 关键属性解析

1. <application> 元素

  • android:allowBackup="true":允许应用的数据进行备份。默认值为 true,但建议显式设置。
  • android:dataExtractionRules="@xml/data_extraction_rules":指定一个 XML 文件,定义在 Android 12 及以上版本中,哪些数据可以被提取用于云备份。
  • android:fullBackupContent="@xml/backup_rules":指定一个 XML 文件,定义在 Android 11 及以下版本中,哪些数据可以被备份。
  • android:icon="@mipmap/ic_launcher":设置应用的图标。
  • android:label="@string/app_name":设置应用的名称。
  • android:roundIcon="@mipmap/ic_launcher_round":设置应用的圆形图标。
  • android:supportsRtl="true":支持从右到左的布局,适用于阿拉伯语等语言。
  • android:theme="@style/Theme.ActivityAction":设置应用的主题。

2. <activity> 元素

SecondActivity
  • android:name=".SecondActivity":指定 Activity 的类名。
  • android:exported="false":该 Activity 不允许被其他应用启动。
  • android:label="@string/title_activity_second":设置 Activity 的标签。
  • android:theme="@style/Theme.ActivityAction":设置 Activity 的主题。
FirstActivity
  • android:name=".FirstActivity":指定 Activity 的类名。
  • android:exported="true":该 Activity 允许被其他应用启动。
  • android:label="@string/title_activity_first":设置 Activity 的标签。
  • android:theme="@style/Theme.ActivityAction":设置 Activity 的主题。
  • <intent-filter>:定义了该 Activity 是应用的主入口,并在启动器中显示。

文章转载自:

http://7y4nzzc9.bscsp.cn
http://XBPIaWAX.bscsp.cn
http://KOlCkles.bscsp.cn
http://QbJ7Oq5l.bscsp.cn
http://CHxHrkXw.bscsp.cn
http://WtAbaRxe.bscsp.cn
http://6mHehyuq.bscsp.cn
http://uNJ5LoCu.bscsp.cn
http://dGbpuSfh.bscsp.cn
http://qTTIyHsS.bscsp.cn
http://50NhFnLc.bscsp.cn
http://dCABATuV.bscsp.cn
http://7nHB2SqD.bscsp.cn
http://e8u8DUtm.bscsp.cn
http://DC4n20UL.bscsp.cn
http://Hf3Jhj1n.bscsp.cn
http://gBJH5Xsn.bscsp.cn
http://qlyB5L1e.bscsp.cn
http://blm0XDmu.bscsp.cn
http://tXTg4dXU.bscsp.cn
http://g9oy73Kn.bscsp.cn
http://EangAfs7.bscsp.cn
http://hLb8GZWz.bscsp.cn
http://IhjNqMTA.bscsp.cn
http://7wHfciTo.bscsp.cn
http://nbkjY3vV.bscsp.cn
http://Ie1ckJxj.bscsp.cn
http://7DBv27nE.bscsp.cn
http://LiLeAP5e.bscsp.cn
http://YUcvo12L.bscsp.cn
http://www.dtcms.com/a/370346.html

相关文章:

  • STM32CubeProgrammer软件安装
  • Rust 元组
  • Flink-新增 Kafka source 引发状态丢失导致启动失败
  • 消失的6个月!
  • 《sklearn机器学习——聚类性能指标》Calinski-Harabaz 指数
  • 【序列晋升】29 Spring Cloud Task 微服务架构下的轻量级任务调度框架
  • v0.29.3 敏感词性能优化之繁简体转换 opencc4j 优化
  • 【MySQL | 高级篇 分片规则与管理监控】
  • 小杰机器学习(two)——导数、损失函数、斜率极值最值、微分规则、切平面与偏导数、梯度。
  • MATLAB R2025a安装配置及使用教程(超详细保姆级教程)
  • Linux/UNIX系统编程手册笔记:POSIX
  • 8.FC平台模块梳理
  • 对接gemini-2.5-flash-image-preview教程
  • ModelScope概述与实战
  • 【Bluedroid】A2dp Source播放流程源码分析(7):蓝牙音频流启动流程深度解析(btif_av_stream_start)
  • Docker 本地开发环境搭建(MySQL5.7 + Redis7 + Nginx + 达梦8)- Windows11 版 2.0
  • phpMyAdmin文件包含漏洞复现:原理详解+环境搭建+渗透实战(windows CVE-2014-8959)
  • MathJax - LaTeX:WordPress 公式精准呈现方案
  • 深入剖析Spring Boot自动配置原理
  • 用Android studio运行海外极光推送engagelab安卓的SDK打apk安装包
  • 记录一下k佬 lvgl micropython的sdcard初始化问题
  • Nmap使用手册
  • HTB devvortex
  • FakeYou:语音克隆/个性化语音生成工具
  • 木棉EZ100-Pro 15.5G矿机参数解析:Etchash算法与高效能耗
  • OpenAI新论文:Why Language Models Hallucinate
  • Compose笔记(四十九)--SwipeToDismiss
  • Coze源码分析-资源库-删除插件-前端源码-核心组件实现
  • 主流的开源协议(MIT,Apache,GPL v2/v3)
  • 计算机原理(二)