当前位置: 代码迷 >> Android >> 研究 android apk装配卸载等 产生的 系统广播
  详细解决方案

研究 android apk装配卸载等 产生的 系统广播

热度:375   发布时间:2016-04-28 07:40:10.0
研究 android apk安装卸载等 产生的 系统广播

想更加清楚的了解 android 系统在安装、卸载时产生的系统广播,于是写了一个 demo 来做监听,

BroadReceiver 配置如下:

        <receiver android:name="com.example.testjni.PackgeReceiver" >            <intent-filter>                <data android:scheme="package" />                <action android:name="android.intent.action.PACKAGE_ADDED" />                <action android:name="android.intent.action.PACKAGE_REMOVED" />                <action android:name="android.intent.action.PACKAGE_CHANGED" />                <action android:name="android.intent.action.PACKAGE_INSTALL" />                <action android:name="android.intent.action.PACKAGE_REPLACED" />                <action android:name="android.intent.action.PACKAGE_DATA_CLEARED" />                <action android:name="android.intent.action.PACKAGE_FIRST_LAUNCH" />                <action android:name="android.intent.action.PACKAGE_RESTARTED" />                <action android:name="android.intent.action.PACKAGE_VERIFIED" />            </intent-filter>        </receiver>

这里有一点要注意,需配置 <data android:scheme="package" /> ,否则收不到广播!


1.当你第一次安装某个应用的时候:

10-19 12:45:47.792: W/System.err(24921): receive android.intent.action.PACKAGE_ADDED10-19 12:45:47.792: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:45:47.792: W/System.err(24921):   dataString package:com.yichou.common.sdk

2.当你第二次安装某个应用的时候:

10-19 12:47:09.679: W/System.err(24921): receive android.intent.action.PACKAGE_REMOVED10-19 12:47:09.679: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:47:09.679: W/System.err(24921):   dataString package:com.yichou.common.sdk10-19 12:47:11.441: W/System.err(24921): receive android.intent.action.PACKAGE_ADDED10-19 12:47:11.441: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:47:11.441: W/System.err(24921):   dataString package:com.yichou.common.sdk10-19 12:47:11.531: W/System.err(24921): receive android.intent.action.PACKAGE_REPLACED10-19 12:47:11.531: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:47:11.531: W/System.err(24921):   dataString package:com.yichou.common.sdk


3.当卸载一个应用的时候:

10-19 12:43:54.381: W/System.err(24921): receive android.intent.action.PACKAGE_REMOVED10-19 12:43:54.381: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:43:54.381: W/System.err(24921):   dataString package:com.yichou.common.sdk

4.当清除应用数据时

10-19 12:49:05.973: W/System.err(24921): receive android.intent.action.PACKAGE_RESTARTED10-19 12:49:05.973: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:49:05.973: W/System.err(24921):   dataString package:com.yichou.common.sdk10-19 12:49:05.993: W/System.err(24921): receive android.intent.action.PACKAGE_DATA_CLEARED10-19 12:49:05.993: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:49:05.993: W/System.err(24921):   dataString package:com.yichou.common.sdk

5.当 点击强制停止后

10-19 12:48:31.587: W/System.err(24921): receive android.intent.action.PACKAGE_RESTARTED10-19 12:48:31.587: W/System.err(24921):   data package:com.yichou.common.sdk10-19 12:48:31.587: W/System.err(24921):   dataString package:com.yichou.common.sdk

5.总结下:

android.intent.action.PACKAGE_RESTARTED 意思为 应用进程重启,当我们点击强制停止后收到此消息,常理你会认为应该在应用再次启动的时候收到。


  相关解决方案