开发学院手机开发Android 开发 Android 代码监控apk安装,卸载,替换 阅读

Android 代码监控apk安装,卸载,替换

 2010-11-05 00:54:46 来源:WEB开发网   
核心提示:Java代码public class GetBroadcast extends BroadcastReceiver {private static GetBroadcast mReceiver = new GetBroadcast();private static IntentFilter mIntentFilter;

Java代码

public class GetBroadcast extends BroadcastReceiver {

private static GetBroadcast mReceiver = new GetBroadcast();

private static IntentFilter mIntentFilter;

public static void registerReceiver(Context context) {

mIntentFilter = new IntentFilter();

mIntentFilter.addDataScheme("package");

mIntentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);

mIntentFilter.addAction(Intent.ACTION_PACKAGE_REMOVED);

mIntentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);

context.registerReceiver(mReceiver, mIntentFilter);

}

public static void unregisterReceiver(Context context) {

context.unregisterReceiver(mReceiver);

}

@Override

public void onReceive(Context context, Intent intent) {

String action = intent.getAction();

if (Intent.ACTION_PACKAGE_ADDED.equals(action)) {

Toast.makeText(context, "有应用被添加", Toast.LENGTH_LONG).show();

} else if (Intent.ACTION_PACKAGE_REMOVED.equals(action)) {

Toast.makeText(context, "有应用被删除", Toast.LENGTH_LONG).show();

}

/*

* else if(Intent.ACTION_PACKAGE_CHANGED.equals(action)){

* Toast.makeText(context, "有应用被改变", Toast.LENGTH_LONG).show(); }

*/

else if (Intent.ACTION_PACKAGE_REPLACED.equals(action)) {

Toast.makeText(context, "有应用被替换", Toast.LENGTH_LONG).show();

}

/*

* else if(Intent.ACTION_PACKAGE_RESTARTED.equals(action)){

* Toast.makeText(context, "有应用被重启", Toast.LENGTH_LONG).show(); }

*/

/*

* else if(Intent.ACTION_PACKAGE_INSTALL.equals(action)){

* Toast.makeText(context, "有应用被安装", Toast.LENGTH_LONG).show(); }

*/

}

}

Tags:Android 代码 监控

编辑录入:coldstar [复制链接] [打 印]
[]
  • 好
  • 好的评价 如果觉得好,就请您
      0%(0)
  • 差
  • 差的评价 如果觉得差,就请您
      0%(0)
更多精彩
    赞助商链接

    热点阅读
      焦点图片
        最新推荐
          精彩阅读