欢迎访问移动开发之家(rcyd.net),关注移动开发教程。移动开发之家  移动开发问答|  每日更新
页面位置 : > > > 内容正文

androidstudio清单配置文件androidmainfest.xml详细解读,

来源: 开发者 投稿于  被查看 2475 次 评论:137

androidstudio清单配置文件androidmainfest.xml详细解读,


目录
  • AndroidManifest是什么?
  • AndroidManifest的作用是什么?
  • 1、注册Activity页面,并指定首页。
  • 2、需要的权限要在此文件中指定;

AndroidManifest是什么?

AndroidManifest官方解释是应用清单(manifest意思是货单),每个应用的根目录中都必须包含一个,并且文件名必须一模一样。这个文件中包含了APP的配置信息,系统需要根据里面的内容运行APP的代码,显示界面。

AndroidManifest的作用是什么?

上述的功能是非常笼统的解释,具体到细节就是:

  • 为应用的 Java 软件包命名。软件包名称充当应用的唯一标识符。
  • 描述应用的各个组件,包括构成应用的 Activity、服务、广播接收器和内容提供程序。它还为实现每个组件的类命名并发布其功能,例如它们可以处理的 Intent 消息。这些声明向 Android 系统告知有关组件以及可以启动这些组件的条件的信息。
  • 确定托管应用组件的进程。
  • 声明应用必须具备哪些权限才能访问 API 中受保护的部分并与其他应用交互。还声明其他应用与该应用组件交互所需具备的权限
  • 列出 Instrumentation类,这些类可在应用运行时提供分析和其他信息。这些声明只会在应用处于开发阶段时出现在清单中,在应用发布之前将移除。
  • 声明应用所需的最低 Android API 级别
  • 列出应用必须链接到的库

上面是官方的解释。很多东西笔者现在还不能理解,也没有用到,先挑笔者理解的进行解释。

  • 第一条:提供软件包名。这就是我们的apk的名字,通常我们的名字都是类似"com.android.gles3jni"这种,和Java类名类似,目的是确定使其成为一个唯一值。

  • 第二条:描述应用的各个组件。这是用来定义四大组件用的。我们最常用的就是Activity组件。它需要定义组件的表现形式(组件名、主题、启动类型),组件可以响应的操作(例如某个启动意图)等。

  • 第三条、第四条和第五条:还没用到,不做解释。

  • 第五条:声明最低API级别。这个级别在build.gradle文件中也能定义,字段是minSdkVersion。在AndroidManifest.xml文件中定义的情况比较少。

  • 第六条:列出必要的lib库。这东西在3.0以后的Android Studio似乎也没什么功能,因为在3.0以后编译用的是CMakeLists.txt文件,以及build.gradle文件来指定库。

接下来接介绍android studio 清单配置文件androidmainfest.xml解读。

1、注册Activity页面,并指定首页。

  所有的页面文件要在此文件中注册。

  指定是APP的首页:(android:exported="true")和下面的 intent-filter中的两行,;

2、需要的权限要在此文件中指定;

 <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools">
    <!-- Needed only if your app looks for Bluetooth devices.
         If your app doesn't use Bluetooth scan results to derive physical
         location information, you can
         <a href="#assert-never-for-location" rel="external nofollow" >strongly assert that your app
         doesn't derive physical location</a>. -->
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <!-- Needed only if your app makes the device discoverable to Bluetooth
         devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
    <!-- Needed only if your app communicates with already-paired Bluetooth
         devices. -->
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
    <application
        android: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.LabelPrint"
        tools:targetApi="31">
        <activity
            android:name=".MainActivity"
            android:exported="true">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
    </application>
</manifest>

到此这篇关于android studio 清单配置文件androidmainfest.xml解读的文章就介绍到这了,更多相关androidmainfest.xml解读内容请搜索3672js教程以前的文章或继续浏览下面的相关文章希望大家以后多多支持3672js教程!

您可能感兴趣的文章:
  • Android Studio配置文件路径修改的方法

用户评论