Android系统通过应用程序自行在系统中登记注册事件(即Intent)来响应系统产生的各类消息。
例如Android实现系统开机自启动程需要在Manifest中加入如下Intent-filter及权限Uses-permission即可。
-
<intent-filter>
-
<action android:name="android.intent.action.BOOT_COMPLETED"/>
- (修改时候主要是去掉上面该行即可)
-
<category android:name="android.intent.category.HOME" />
-
</intent-filter>
- <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
- (修改时候主要是去掉上面该行即可)
Android系统为应用程序管理功能提供了大量的API,可以通过API控制Intent和permission,其中
上述配置表示应用程序会响应系统产生的android.intent.action.BOOT_COMPLETED(系统启动完成)信号,以此来实现应用程序自启动。当然知道上述原理后,我们就可以随心所欲的控制程序开机自启动了。具体思路如下:
一、手工方法
基于上述原理,我们可以通过对系统中已安装的程序去除其Manifest的上述配置片段来控制应用程序的对系统的响应,当然没源码可修改编译的情况下只能实现屏蔽其对有些信号的响应,例如屏蔽该程序不再开机自启动。手工方法就是利用有关工具直接在解压其APK包后,修改其Manifest的上述配置行后再打包成APK,最后安装到系统中就实现了屏蔽其自启动功能。具体相关的工具软件主要有APKTOOL。(请自己放狗去搜索下载)
二、编程实现
当然手工方法需要借助APKTOOL等工具,步骤比较法繁琐,我们可以通过自己开发来实现该功能。幸好
1、PackageManager
本类API是对所有基于加载信息的数据结构的封装,包括以下功能:
•安装,卸载应用
•查询permission相关信息
•查询Application相关信息(application,activity,receiver,service,provider及相应属性等)
•查询已安装应用
•增加,删除permission
•清除用户数据、缓存,代码段等
非查询相关的API需要特定的权限,具体的API请参考SDK文档。
2、ActivityManager相关
本类API是对运行时管理功能和运行时数据结构的封装,包括以下功能
•激活/去激活activity
•注册/取消注册动态接受intent
•发送/取消发送intent
•activity生命周期管理(暂停,恢复,停止,销毁等)
•activity task管理(前台->后台,后台->前台,最近task查询,运行时task查询)
•激活/去激活service
•激活/去激活provider等
task管理相关API需要特定的权限,具体API可参考SDK文档。
利用上述API原理的具体代码俺有空时候试试实现一个,应该不难的,都是调用现成的API实现。目前发现已有的控制开机自启动的成熟应用程序主要是autostarts,可自己安装一个试试,挺好用,实际上autostart有点名不副实,如果是我就会起个名字叫Intentcontrol,因为其不只是控制开机启动信号,它可以控制程序对大部分信号的响应行为。
三、系统自带工具
Android自带了1、程序包管理工具:/system/bin/pm 2、activity管理工具:/system/bin/am
具体用法大致说明如下:
pm的使用方法可以参考
usage: pm [list|path|install|uninstall]
pm list packages [-f]
pm list permission-groups
pm list permissions [-g] [-f] [-d] [-u] [GROUP]
pm list instrumentation [-f] [TARGET-PACKAGE]
pm list features
pm path PACKAGE
pm install [-l] [-r] [-t] [-i INSTALLER_PACKAGE_NAME] PATH
pm uninstall [-k] PACKAGE
pm enable PACKAGE_OR_COMPONENT
pm disable PACKAGE_OR_COMPONENT
The list packages command prints all packages. Options:
-f: see their associated file.
The list permission-groups command prints all known
permission groups.
The list permissions command prints all known
permissions, optionally only those in GROUP. Options:
-g: organize by group.
-f: print all information.
-s: short summary.
-d: only list dangerous permissions.
-u: list only the permissions users will see.
The list instrumentation command prints all instrumentations,
or only those that target a specified package. Options:
-f: see their associated file.
The list features command prints all features of the system.
The path command prints the path to the .apk of a package.
The install command installs a package to the system. Options:
-l: install the package with FORWARD_LOCK.
-r: reinstall an exisiting app, keeping its data.
-t: allow test .apks to be installed.
-i: specify the installer package name.
The uninstall command removes a package from the system. Options:
-k: keep the data and cache directories around.
after the package removal.
The enable and disable commands change the enabled state of
a given package or component (written as "package/class").
am的使用方法可以参考
usage: am [subcommand] [options]
start an Activity: am start [-D] <INTENT>
-D: enable debugging
send a broadcast Intent: am broadcast <INTENT>
start an Instrumentation: am instrument [flags] <COMPONENT>
-r: print raw results (otherwise decode REPORT_KEY_STREAMRESULT)
-e <NAME> <VALUE>: set argument <NAME> to <VALUE>
-p <FILE>: write profiling data to <FILE>
-w: wait for instrumentation to finish before returning
start profiling: am profile <PROCESS> start <FILE>
stop profiling: am profile <PROCESS> stop
<INTENT> specifications include these flags:
[-a <ACTION>] [-d <DATA_URI>] [-t <MIME_TYPE>]
[-c <CATEGORY> [-c <CATEGORY>] ...]
[-e|--es <EXTRA_KEY> <EXTRA_STRING_VALUE> ...]
[--ez <EXTRA_KEY> <EXTRA_BOOLEAN_VALUE> ...]
[-e|--ei <EXTRA_KEY> <EXTRA_INT_VALUE> ...]
[-n <COMPONENT>] [-f <FLAGS>] [<URI>]
分享到:
相关推荐
Android 开机自启动应用, BOOT_COMPLETED
可以实现手机开机重启的时候自启动,程序简单易懂,有注释,是利用广播实现的
实现Android 开机自启动程序,BroadCastReceiver
现在大多数的android手机系统都默认禁止第三方安装的APP开机自启动,只有系统APP(system/app)才默认有这个权限,所以一般都需要去安全中心或者手机管家中去设置为允许。这里说个题外话,手机软件除非特殊情况,不然...
android开机自动启动service例子 android开机自动启动service例子
【Android】开机自启动Demo 相关文章:http://blog.csdn.net/etzmico/article/details/6848465
动态设置开机启动程序
Android应用开机自动启动代码Demo,下载后直接放在Android Studio里运行就可以
Android 开机自启动示例程序。使用广播方式接受,采用Android自带存储shareference存储开机自启动的设置。
实现android开机自启动,用广播实现自启动
【Android】开机自启动Service Demo 相关文章链接:http://blog.csdn.net/etzmico/article/details/7317695
android最好的开机自启动项管理软件,软件暂用资源小,功能强大,绿色无广告~~极力推荐
android程序开机自启动示例,源代码
Android应用程序可以实现开机时启动相关应用 如service等 Android系统在开机启动时会发出一个系统广播"android intent action BOOT COMPLETED" 在接收到这个广播就可以实现开机自启动功能 下面就是一个...
delphi ex10 android 实现开机自启动.rar
该程序基于android平台可以实现开机自动启动录音 并且将录音存储在当前存储目录下
Delphi xe6 编译通过,android开机启动程序,含各种使用方法。
Android开机自动运行一个程序教程
客户需要开机后自动启动wifi-adb服务,所以就在程序里加了一下,开机后会自动打开wifi-adb连接服务,前提是的设备wifi是ok的,就可以通过wifi 来连接adb了。