Android Launcher manifest解析

Launcher 的AndroidManifest.xml文件有很多特殊性,分析一下就会理解整个程序的大概结构。
代码如下:
< manifest xmlns:android = "http://schemas.android.com/apk/res/android"
package = "net.sunniwell.launcher"
android:versionCode = "1" android:versionName = "1.0.1" >

关于自定义权限,这是很好的例子,其他 apk 程序要想使用 Launcher 的功能必须添加这些权限,而这些权限都是在这里声明的。

这个是安装快捷方式的权限定义:

< permission
android:name = "com.android.launcher.permission.INSTALL_SHORTCUT"
android:permissionGroup = "android.permission-group.SYSTEM_TOOLS"
android:protectionLevel = "normal"
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 = "normal"
android:label = "@string/permlab_uninstall_shortcut"
android:description = "@string/permdesc_uninstall_shortcut" />


这个是读取 launcher.db 内容的权限定义:

< permission
android:name = "net.sunniwell.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" />


这个是修改和删除 launcher.db 内容的权限定义:

< permission
android:name = "net.sunniwell.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" />

这些是 Launcher 的权限声明,通过这些就能看出 launcher 的大概功能了:
打电话权限:

< uses-permission android:name = "android.permission.CALL_PHONE" />

使用状态栏权限:

< uses-permission android:name = "android.permission.EXPAND_STATUS_BAR" />

获取当前或最近运行的任务的信息的权限:

< uses-permission android:name = "android.permission.GET_TASKS" />

读取通信录权限 :

< uses-permission android:name = "android.permission.READ_CONTACTS" />

设置壁纸权限:
< uses-permission android:name = "android.permission.SET_WALLPAPER" />

允许程序设置壁纸 hits 的权限:
< uses-permission android:name = "android.permission.SET_WALLPAPER_HINTS" />

使用震动功能权限:
< uses-permission android:name = "android.permission.VIBRATE" />

修改删除 launcher.db 内容权限:
< uses-permission android:name = "android.permission.WRITE_SETTINGS" />

绑定 widget 权限:
< uses-permission android:name = "android.permission.BIND_APPWIDGET" />

读取 launcher.db 内容权限:
< uses-permission android:name = "net.sunniwell.launcher.permission.READ_SETTINGS" />

修改删除 launcher.db 内容权限:
< uses-permission android:name = "net.sunniwell.launcher.permission.WRITE_SETTINGS" />

读写外部存储设备权限:
< uses-permission android:name = "android.permission.WRITE_EXTERNAL_STORAGE" ></ uses-permission >


< application
android:name = "LauncherApplication"
activity 应该运行的进程的名字:
android:process = "android.process.acore"
android:label = "@string/application_name"
android:icon = "@drawable/swicon" >


< activity
android:name = "Launcher"
是否
android:launchMode = "singleTask"
android:clearTaskOnLaunch = "true"
这个 activity 是否在被杀死或者重启后能恢复原来的状态:
android:stateNotNeeded = "true"
android:theme = "@style/Theme"
android:screenOrientation = "landscape"
android:windowSoftInputMode = "stateUnspecified|adjustPan" >

< intent-filter >

< action android:name = "android.intent.action.MAIN" />

< category android:name = "android.intent.category.LAUNCHER" />


桌面应用的标记:
< category android:name = "android.intent.category.HOME" />

< category android:name = "android.intent.category.DEFAULT" />

自动化测试工具 Monkey 的标记,待研究 …
< category android:name = "android.intent.category.MONKEY" />


</ intent-filter >

</ activity >

选择壁纸的 activity:
< activity
android:name = "WallpaperChooser"
android:label = "@string/pick_wallpaper"
android:icon = "@drawable/ic_launcher_gallery" >


设置壁纸的 intent-filter :

< intent-filter >

< action android:name = "android.intent.action.SET_WALLPAPER" />

< category android:name = "android.intent.category.DEFAULT" />

</ intent-filter >

搜索的 activity :
</ activity >

<!-- Enable system-default search mode for any activity in Home -->

< meta-data
android:name = "android.app.default_searchable"
android:value = "*" />

安装快捷方式的广播接收器:

<!-- Intent received used to install shortcuts from other applications -->


< 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 >

<!-- Intent received used to uninstall shortcuts from other applications -->

卸载快捷方式的广播接收器:

< receiver
android:name = ".UninstallShortcutReceiver"
android:permission = "com.android.launcher.permission.UNINSTALL_SHORTCUT" >

< intent-filter >

< action android:name = "com.android.launcher.action.UNINSTALL_SHORTCUT" />

</ intent-filter >

</ receiver >

声明 ContentProvider ,用于对 launcher.db 操作:

<!-- The settings provider contains Home's data, like the workspace favorites -->

< provider
android:name = "SWLauncherProvider"
android:authorities = "net.sunniwell.launcher.settings"
android:writePermission = "net.sunniwell.launcher.permission.WRITE_SETTINGS"
android:readPermission = "net.sunniwell.launcher.permission.READ_SETTINGS" />

</ application >

< uses-sdk android:minSdkVersion = "4" />
</ manifest >

说明:
1.
<manifest 标签头部还应声明:
android:sharedUserId="android.uid.shared" ,作用是获得系统权限,但是这样的程序属性只能在build整个系统时放进去(就是系统软件)才起作用,手动安装是没有权限的。
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android LauncherAndroid系统上的一个应用程序,它是用户与系统交互的主要界面,也是用户启动应用程序的入口。它允许用户查看、操作和管理应用程序、小部件和系统功能。 Android Launcher的源码解析涉及到多个关键组件和类。其中最重要的是LauncherActivity、PackageManager、AppWidgetManager和DesktopPane。 LauncherActivity是应用程序启动的入口点。它负责显示主屏幕和响应用户的触摸事件。在LauncherActivity中,使用了ViewPager来创建多个屏幕来容纳应用程序和小部件。 PackageManager是应用程序的管理器。通过PackageManager,Launcher可以获取系统中安装的应用程序信息、启动应用程序和监听应用程序的安装、卸载等事件。 AppWidgetManager用于管理应用程序的小部件。Launcher通过AppWidgetManager注册、更新和删除小部件。它还负责接收小部件的更新事件。 DesktopPane是主屏幕的容器。它使用GridLayout将应用程序和小部件布局在主屏幕上。DesktopPane还处理用户在主屏幕上的拖放操作,允许用户重新排序应用程序和小部件。 在源码解析过程中,还需要了解Android应用程序交互的一些核心概念,如Intent、Broadcast和Service等。Intent用于在组件之间传递消息,Broadcast用于传递系统事件,Service用于在后台执行任务。 在分析Launcher源码时,还需要关注性能优化和用户体验。例如,使用异步加载和缓存来提高应用程序和小部件的加载速度,使用动画效果来增强界面的流畅性。 综上所述,Android Launcher源码解析涉及多个组件和类,需要了解Android应用程序交互的核心概念,同时需要关注性能优化和用户体验。这个过程可以帮助开发者深入理解和定制Android系统的启动器。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值