最近手机上常被偷偷安装一些垃圾程序,就想写个小工具来记录一下是哪个程序安装的,搜了一圈,发现程序安装后会广播消息:ACTION_PACKAGE_ADDED,不过这个消息好像是系统发出的,能不能查询到触发这个消息的应用程序名称呢?或者大家有啥其他好的监视程序安装的方法呢

解决方案 »

  1.   

    程序安装完会系统自己发出ACTION_PACKAGE_ADDED,   但是从这里并不能为我们提供任何线索,到底是谁安装的应用程序。 可以从 ACTION_PACKAGE_FIRST_LAUNCH 或者 ACTION_PACKAGE_INSTALL  下手,会容易些。看你的描述,好像拿不到系统源码修改不了系统log,现在可以从现有的logcat里得到什么信息吗 ? 
      

  2.   

    这个广播新装的包自己不会收到,广播内也没说明是安装了什么,可以看手册。每次收到广播记录查询一次安装程序比较一次
    获取Android系统中已安装程序的名字、包名等信息
    http://mm.10086.cn/buluo/topic.php?tid=867手册说明:
    public static final String ACTION_PACKAGE_ADDED
    Since: API Level 1Broadcast Action: A new application package has been installed on the device. The data contains the name of the package. Note that the newly installed package does not receive this broadcast.
    My include the following extras:
        * EXTRA_UID containing the integer uid assigned to the new package.
        * EXTRA_REPLACING is set to true if this is following an ACTION_PACKAGE_REMOVED broadcast for the same package. 
    This is a protected intent that can only be sent by the system.
    Constant Value: "android.intent.action.PACKAGE_ADDED"
      

  3.   

    这个问题很nice, 可以好好研究研究,ACTION_PACKAGE_ADDED只能得到安装的 package name 和UID ,但是没有哪个安装滴信息记录,可以好好研究研究