Android Launcher 开发研究学习


Launcher是系统启动后第一个启动的程序,是其它应用程序的入口,也就是我们的手机程序的桌面程序;

一、Launcher的定义及构成:

<1>通过查看官方提供的Launcher源码可以知道其实Launcher也是一个Activity,不过它的intent-fliter有点特殊;

        <activity
            Android:name="Launcher"
            android:launchMode="singleTask"
            android:clearTaskOnLaunch="true"
            android:stateNotNeeded="true"
            android:theme="@android:style/Theme.Wallpaper.NoTitleBar"
            android:screenOrientation="nosensor"
            android:windowSoftInputMode="stateUnspecified|adjustPan">
            <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>

Launcher的intent-filter中,action为intent.action.MAIN,表示该Activity是程序的主入口,但是它的category是category.HOME,和一般的app不一样,category.HOME则标识了这个Activity是一个Launcher,其实就是对应的按下HOME键所跳转到的Activity,也就是我们的桌面;

下面我们再来看一下一个普通的App的程序主入口Activity的配置:

<action android:name="android.intent.action.MAIN" /> 表示该类是程序主入口;
<category android:name="android.intent.category.LAUNCHER" /> 

category.LAUNCHER表示该Activity在Launcher上可见,所以这一个Activity会被添加到Launcher;

<2>Launcher构成:
HomeScreen(WorkSpace+HotSeats),Shortcut(快捷方式),LiveFolder(文件夹),AppWidget(窗口小部件),WallPaper(壁纸);
AllAppList:

下面我们就来分别研究探讨这四个元素

1、Shortcut
在Launcher的配置文件里面有这样一个广播接收者用于监听添加快捷方式

        <receiver
            android:name=".InstallShortcutReceiver"
            android:permission="com.android.launcher.permission.INSTALL_SHORTCUT">
            <intent-filter>
                <action android:name="com.android.launcher.action.INSTALL_SHORTCUT" />
            </intent-filter>
        </receiver>

查看InstallShortcutReceiver的源码

相关内容