您的位置:首页 > 移动开发 > Android开发

Android4.2_Launcher_AndroidMainfest.xml

2014-08-08 10:18 344 查看
AndroidMainifest.xml 列出了Launcher 向系统提供的基本信息,包括包名,用到的组件(Activity,Service,Receiver,ContentProvider)。声明了它需要用到的权限,以及自己定义的权限。

在这个 AndroidMainifest.xml 文件,它主要做了这样几件事:

1. 定义了自己的权限,告诉外其他程序,如果需要用 Launcher的话,需要声明这些权限。

2. 申请了自己需要用到的权限。包括打电话,设置壁纸,读取与写设置(这两个使用了自己定义的权限),

3. 声明了这个程序使用的 Application 实例。

4. 声明了这个程序的主 Activity 及其它 Activity,主 Activity 即 Launcher Activity,同时用IntentFilter来接收广播启动。如果我们要写自己的 Launcher,就需要使用一样的 IntentFilter。WallpaperChooser
是Launcher的第二个 Activity,从名字可以判断应该是 选择壁纸时调用的。这个 Activity 当接收到"android.intent.action.SET_WALLPAPER" 广播时会启动。

5. 声明了4个Receiver,注释中已经告诉这三个 Receiver的用途了。分别是:

Intent received used to prepopulate the default workspace,根据名字应该是预加载 workspace的广播。

Intent received used to install shortcuts from other applications 应用程序建立快捷方式的广播

Intent received used to uninstall shortcuts from other applications 应用程序删除快捷方式的广播。

New user initialization; set up initial wallpape 应该是检测到是新用户时,来设置壁纸。

6. 声明了一个 Provider, 主要用来向外界提供服务,需要Launcher自己定义的权限 读设置和写设置。

7. 为Application节点声明了一个<meta-data>。这个值在应用程序中会被这样读取:

ApplicationInfo appInfo = this.getPackageManager()
                                  .getApplicationInfo(getPackageName(),
                          PackageManager.GET_META_DATA);
    String msg=appInfo.metaData.getString("android.nfc.disable_beam_default");


上面就是 Launcher 的清单文件主要做的事情了。从这里可以看出初始化主要在 Application 的 onCreate 和 Launcher Activity 的 onCreate中完成。

<?xml version="1.0" encoding="utf-8"?>
<!--
/*
**
** Copyright 2008, 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.
*/
-->
<manifest
    xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.android.launcher">

    <original-package android:name="com.android.launcher2" />

    <permission
        android:name="com.android.launcher.permission.PRELOAD_WORKSPACE"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="system|signature" />
    <permission
        android:name="com.android.launcher.permission.INSTALL_SHORTCUT"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="dangerous"
        android:label="@string/permlab_install_shortcut"
        android:description="@string/permdesc_install_shortcut" />
    <permission
        android:name="com.android.launcher.permission.UNINSTALL_SHORTCUT"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="dangerous"
        android:label="@string/permlab_uninstall_shortcut"
        android:description="@string/permdesc_uninstall_shortcut"/>
    <permission
        android:name="com.android.launcher.permission.READ_SETTINGS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="normal"
        android:label="@string/permlab_read_settings"
        android:description="@string/permdesc_read_settings"/>
    <permission
        android:name="com.android.launcher.permission.WRITE_SETTINGS"
        android:permissionGroup="android.permission-group.SYSTEM_TOOLS"
        android:protectionLevel="normal"
        android:label="@string/permlab_write_settings"
        android:description="@string/permdesc_write_settings"/>

    <uses-permission android:name="android.permission.CALL_PHONE" />
    <uses-permission android:name="android.permission.SET_WALLPAPER" />
    <uses-permission android:name="android.permission.SET_WALLPAPER_HINTS" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <uses-permission android:name="android.permission.BIND_APPWIDGET" />
    <uses-permission android:name="android.permission.GET_ACCOUNTS" />
    <uses-permission android:name="com.android.launcher.permission.READ_SETTINGS" />
    <uses-permission android:name="com.android.launcher.permission.WRITE_SETTINGS" />

    <application
        android:name="com.android.launcher2.LauncherApplication"
        android:label="@string/application_name"
        android:icon="@mipmap/ic_launcher_home"
        android:hardwareAccelerated="true"
        android:largeHeap="@bool/config_largeHeap"
        android:supportsRtl="true">
        <activity
            android:name="com.android.launcher2.Launcher"
            android:launchMode="singleTask"
            android:clearTaskOnLaunch="true"
            android:stateNotNeeded="true"
            android:theme="@style/Theme"
            android:windowSoftInputMode="adjustPan"
            android:screenOrientation="nosensor">
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.HOME" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.MONKEY"/>
            </intent-filter>
        </activity>

        <activity
            android:name="com.android.launcher2.WallpaperChooser"
            android:theme="@style/Theme.WallpaperPicker"
            android:label="@string/pick_wallpaper"
            android:icon="@mipmap/ic_launcher_wallpaper"
            android:finishOnCloseSystemDialogs="true"
            android:process=":wallpaper_chooser">
            <intent-filter>
                <action android:name="android.intent.action.SET_WALLPAPER" />
                <category android:name="android.intent.category.DEFAULT" />
            </intent-filter>
            <meta-data android:name="android.wallpaper.preview"
                android:resource="@xml/wallpaper_picker_preview" />
        </activity>

        <!-- Intent received used to prepopulate the default workspace. -->
        <receiver
            android:name="com.android.launcher2.PreloadReceiver"
            android:permission="com.android.launcher.permission.PRELOAD_WORKSPACE">
            <intent-filter>
                <action android:name="com.android.launcher.action.PRELOAD_WORKSPACE" />
            </intent-filter>
        </receiver>

        <!-- Intent received used to install shortcuts from other applications -->
        <receiver
            android:name="com.android.launcher2.InstallShortcutReceiver"
            android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
            <intent-filter>
                <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
            </intent-filter>
        </receiver>

        <!-- Intent received used to uninstall shortcuts from other applications -->
        <receiver
            android:name="com.android.launcher2.UninstallShortcutReceiver"
            android:permission="com.android.launcher.permission.UNINSTALL_SHORTCUT">
            <intent-filter>
                <action android:name="com.android.launcher.action.UNINSTALL_SHORTCUT" />
            </intent-filter>
        </receiver>

        <!-- New user initialization; set up initial wallpaper -->
        <receiver
            android:name="com.android.launcher2.UserInitializeReceiver"
            android:exported="false">
            <intent-filter>
                <action android:name="android.intent.action.USER_INITIALIZE" />
            </intent-filter>
        </receiver>
        
        <!-- The settings provider contains Home's data, like the workspace favorites -->
        <provider
            android:name="com.android.launcher2.LauncherProvider"
            android:authorities="com.android.launcher2.settings"
            android:exported="true"
            android:writePermission="com.android.launcher.permission.WRITE_SETTINGS"
            android:readPermission="com.android.launcher.permission.READ_SETTINGS" />

        <meta-data android:name="android.nfc.disable_beam_default"
                       android:value="true" />
    </application>
</manifest>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: