private class MyReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
// TODO Auto-generated method stub
if(intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)){
//Toast.makeText(context, intent.getDataString().substring(8), 2000).show();
String packName = intent.getDataString().substring(8);
//packName为所安装的程序的包名
packagNameList.add(packName);
}
}
}
//监听系统新安装程序的广播
receiver = new MyReceiver();
IntentFilter filter = new IntentFilter(Intent.ACTION_PACKAGE_ADDED);
filter.addDataScheme("package"); //必须添加这项,否则拦截不到广播
registerReceiver(receiver, filter);