码迷,mamicode.com
首页 > 移动开发 > 详细

安卓监听apk的安装和卸载

时间:2014-09-25 16:57:19      阅读:147      评论:0      收藏:0      [点我收藏+]

标签:android   io   ar   文件   sp   art   cti   on   c   

1、创建广播类,继承BroadcastReceiver

public class PackageBroadCastReceiver extends BroadcastReceiver {
  private static final int PACKAGE_NAME_START_INDEX = 8;

 @Override
 public void onReceive(Context context, Intent intent) {
  if (intent == null) {
   return;
  }
  if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) {
  String data = intent.getDataString();

  if (data == null || data.length() <= PACKAGE_NAME_START_INDEX) {
   return;
 }
  String packageName = data.substring(PACKAGE_NAME_START_INDEX);
 }
  }
}
2、在manifest文件中添加声明

<receiver android:name=".PackageBroadCastReceiver">
           <intent-filter>
              <action android:name="android.intent.action.PACKAGE_ADDED" />
              <action android:name="android.intent.action.PACKAGE_REMOVED" />
              <data android:scheme="package" />
              </intent-filter>
</receiver> 

安卓监听apk的安装和卸载

标签:android   io   ar   文件   sp   art   cti   on   c   

原文地址:http://blog.csdn.net/leehu1987/article/details/39552115

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!