A006-AndroidManifest.xml文件解析

作者: IT_xiao小巫 | 来源:发表于2015-08-11 08:33 被阅读219次

    AndroidManifest.xml这个文件在Android中很重要,包含了应用程序的所有配置,包含SDK版本、应用权限、四大组件、扩展数据等等,它包含很多标签,每个标签都有具体的作用,标签下都会有不同的属性,也有通用的属性,不同的属性可能会影响我们应用程序的效果,所以我们详细了解具体标签的具体属性的使用场景是非常必要的,下面笔者会以做过的一个项目的完整配置来给大家系统介绍一下这个文件的使用方法。

    AndroidManifest.xml配置例子

    <?xml version="1.0" encoding="utf-8" standalone="no"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.infzm.o2o"
        android:versionCode="1"
        android:versionName="1.0.2" >
    
        <uses-sdk
            android:minSdkVersion="14"
            android:targetSdkVersion="19" />
    
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.READ_LOGS" />
        <uses-permission android:name="com.android.vending.CHECK_LICENSE" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission android:name="android.permission.VIBRATE" />
        <uses-permission android:name="android.permission.WRITE_SETTINGS" />
        <uses-permission android:name="android.permission.CALL_PHONE"/>
    
        <!-- 极光推送需要配置的权限 -->
        <permission
            android:name="com.infzm.o2o.permission.JPUSH_MESSAGE"
            android:protectionLevel="signature" />
    
        <!-- Required  一些系统要求的权限,如访问网络等 -->
        <uses-permission android:name="com.infzm.o2o.permission.JPUSH_MESSAGE" />
        <uses-permission android:name="android.permission.RECEIVE_USER_PRESENT" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.WAKE_LOCK" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.WRITE_SETTINGS" />
        <uses-permission android:name="android.permission.VIBRATE" />
        <uses-permission android:name="android.permission.MOUNT_UNMOUNT_FILESYSTEMS" />
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
    
        <!-- Optional for location -->
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_LOCATION_EXTRA_COMMANDS" />
        <uses-permission android:name="android.permission.CHANGE_NETWORK_STATE" />
    
        <!-- 极光推送权限配置end -->
    
    
        <!-- 友盟升级权限配置start -->
        <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
        <uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
        <uses-permission android:name="android.permission.READ_PHONE_STATE" />
        <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
        <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
        <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
        <uses-permission android:name="android.permission.INTERNET" />
        <uses-permission android:name="android.permission.READ_LOGS" />
        <uses-permission android:name="android.permission.CALL_PHONE" />
    
        <!-- Permission for Unit Test -->
        <uses-permission android:name="android.permission.GET_TASKS" />
        <!-- 友盟升级权限配置end -->
    
        <application
            android:name=".global.O2OApplication"
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name="com.infzm.o2o.activity.SplashActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
                <intent-filter>
                    <action android:name="android.intent.action.MAIN" />
    
                    <category android:name="android.intent.category.LAUNCHER" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.MainActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:uiOptions="" >
                <meta-data
                    android:name="android.support.UI_OPTIONS"
                    android:value="splitActionBarWhenNarrow" />
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.SettingsFeedback"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.BrowserActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.AboutUsActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.MoreSettingActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.SignUpActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.LoginAcivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.AddressActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan|stateHidden" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.CameristInfoActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.ThemeInfolActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.SettingActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.ReserveActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan|stateHidden" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.OrderReserveActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.OrderCheckActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.PictureActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@style/PicShowTheme" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.OrderDetailActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.ForgetpasswordActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.MyFavoritesActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.WelcomeGuideActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" 
                android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen">
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.ClipImageViewActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.MeActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.OnlineSelectPic"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.ImagePagerActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.CalendarViewActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
            <activity
                android:name="com.infzm.o2o.activity.MessageActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
             <activity
                android:name="com.infzm.o2o.activity.CameristCommentActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait" >
            </activity>
             <activity
                android:name="com.infzm.o2o.activity.PayActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                android:windowSoftInputMode="adjustPan|stateVisible"
                >
            </activity>
             <activity
                android:name="com.infzm.o2o.activity.MessageDetailActivity"
                android:label="@string/app_name"
                android:screenOrientation="portrait"
                >
            </activity>
    
            <!-- 极光推送配置 -->
            <!-- Required SDK核心功能 -->
            <activity
                android:name="cn.jpush.android.ui.PushActivity"
                android:configChanges="orientation|keyboardHidden"
                android:theme="@android:style/Theme.Translucent.NoTitleBar" >
                <intent-filter>
                    <action android:name="cn.jpush.android.ui.PushActivity" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="com.infzm.o2o" />
                </intent-filter>
            </activity>
            <!-- Required  SDK核心功能 -->
            <service
                android:name="cn.jpush.android.service.DownloadService"
                android:enabled="true"
                android:exported="false" >
            </service>
    
            <!-- Required SDK 核心功能 -->
            <service
                android:name="cn.jpush.android.service.PushService"
                android:enabled="true"
                android:exported="false" >
                <intent-filter>
                    <action android:name="cn.jpush.android.intent.REGISTER" />
                    <action android:name="cn.jpush.android.intent.REPORT" />
                    <action android:name="cn.jpush.android.intent.PushService" />
                    <action android:name="cn.jpush.android.intent.PUSH_TIME" />
                </intent-filter>
            </service>
    
            <!-- Required SDK核心功能 -->
            <receiver
                android:name="cn.jpush.android.service.PushReceiver"
                android:enabled="true" >
                <intent-filter android:priority="1000" >
                    <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED_PROXY" />
                    <!-- Required  显示通知栏 -->
                    <category android:name="com.infzm.o2o" />
                </intent-filter>
                <intent-filter>
                    <action android:name="android.intent.action.USER_PRESENT" />
                    <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
                </intent-filter>
                <!-- Optional -->
                <intent-filter>
                    <action android:name="android.intent.action.PACKAGE_ADDED" />
                    <action android:name="android.intent.action.PACKAGE_REMOVED" />
    
                    <data android:scheme="package" />
                </intent-filter>
            </receiver>
    
            <!-- Required SDK核心功能 -->
            <receiver android:name="cn.jpush.android.service.AlarmReceiver" />
    
            <!-- User defined.  For test only  用户自定义的广播接收器 -->
            <receiver
                android:name="com.infzm.o2o.receiver.MyReceiver"
                android:enabled="true" >
                <intent-filter>
                    <action android:name="cn.jpush.android.intent.REGISTRATION" />
                    <!-- Required  用户注册SDK的intent -->
                    <action android:name="cn.jpush.android.intent.UNREGISTRATION" />
                    <action android:name="cn.jpush.android.intent.MESSAGE_RECEIVED" />
                    <!-- Required  用户接收SDK消息的intent -->
                    <action android:name="cn.jpush.android.intent.NOTIFICATION_RECEIVED" />
                    <!-- Required  用户接收SDK通知栏信息的intent -->
                    <action android:name="cn.jpush.android.intent.NOTIFICATION_OPENED" />
                    <!-- Required  用户打开自定义通知栏的intent -->
                    <action android:name="cn.jpush.android.intent.ACTION_RICHPUSH_CALLBACK" />
                    <!-- Optional 用户接受Rich Push Javascript 回调函数的intent -->
                    <action android:name="cn.jpush.android.intent.CONNECTION" />
                    <!-- 接收网络变化 连接/断开 since 1.6.3 -->
                    <category android:name="com.infzm.o2o" />
                </intent-filter>
            </receiver>
    
            <!-- Required  . Enable it you can get statistics data with channel -->
            <meta-data
                android:name="JPUSH_CHANNEL"
                android:value="developer-default" />
            <meta-data
                android:name="JPUSH_APPKEY"
                android:value="815b618e1263a55325d958f1" />
            <!-- </>值来自开发者平台取得的AppKey -->
            <!-- 极光推送配置end -->
    
    
            <!-- 友盟更新sdk -->
    
    
            <!-- Update Activitys Start -->
            <activity
                android:name="com.umeng.update.UpdateDialogActivity"
                android:theme="@android:style/Theme.Translucent.NoTitleBar" >
            </activity>
    
            <!-- Update Activitys End -->
    
    
            <!-- Caution! Do not change this app key. It is only for demo usage. -->
            <meta-data
                android:name="UMENG_APPKEY"
                android:value="552c9094fd98c5ee45000866" >
            </meta-data>
            <meta-data
                android:name="UMENG_CHANNEL"
                android:value="Umeng" >
            </meta-data>
    
            <service
                android:name="com.umeng.update.net.DownloadingService"
                android:process=":DownloadingService" >
            </service>
    
            <!-- 友盟更新end -->
    
    
            <!-- 友盟分享配置start -->
            <!-- ###################注册SDK使用的Activity###################### -->
            <!-- 分享编辑页 -->
            <activity
                android:name="com.umeng.socialize.view.ShareActivity"
                android:configChanges="orientation|keyboard"
                android:launchMode="singleTask"
                android:noHistory="true"
                android:theme="@style/Theme.UMDialog"
                android:windowSoftInputMode="stateVisible|adjustResize" >
            </activity>
    
            <!-- ############ QQ空间和QQ SSO授权的Activity注册 ############ -->
            <activity
                android:name="com.tencent.tauth.AuthActivity"
                android:launchMode="singleTask"
                android:noHistory="true" >
                <intent-filter>
                    <action android:name="android.intent.action.VIEW" />
    
                    <category android:name="android.intent.category.DEFAULT" />
                    <category android:name="android.intent.category.BROWSABLE" />
                    <!-- 100424468,如果你使用的公用账号,则不需要修改;否则修改成你在QQ开放平台申请的 APP ID -->
                    <data android:scheme="tencent100424468" />
                </intent-filter>
            </activity>
            <activity
                android:name="com.tencent.connect.common.AssistActivity"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Translucent.NoTitleBar" >
            </activity>
            <activity
                android:name=".wxapi.WXEntryActivity"
                android:configChanges="keyboardHidden|orientation|screenSize"
                android:exported="true"
                android:screenOrientation="portrait"
                android:theme="@android:style/Theme.Translucent.NoTitleBar" />
            <!-- 友盟分享配置end -->
        </application>
    
    </manifest>
    

    看到上面这么多配置,初学者可能会疯掉,大呼:“这什么鬼啊?看不懂,看不懂?大家先不要怕,其实它就只是个xml文件,先了解一下xml文件的结构,我们知道一个xml文件都会有

    • xml标准文件头
    • 根元素
    • 子元素

    我们每次创建项目会默认为我们创建这个文件,刚开始是这样的

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android="http://schemas.android.com/apk/res/android"
        package="com.devilwwj.pulltorefreshlistview" >
    
        <application
            android:allowBackup="true"
            android:icon="@drawable/ic_launcher"
            android:label="@string/app_name"
            android:theme="@style/AppTheme" >
            <activity
                android:name=".MainActivity"
                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>
    
    </manifest>
    
    

    后面随着我们开发才不断往这个文件添加必须的配置。

    相关文章

      网友评论

        本文标题:A006-AndroidManifest.xml文件解析

        本文链接:https://www.haomeiwen.com/subject/pgsiqttx.html