监听监听,顾名思义就要有broadcast和receive了。
//监听到安装新应用后的处理..BroadcastReceiver installedBr = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) {//有新的应用安装,主要是"android.intent.action.PACKAGE_ADDED" if (intent.getAction() .equals("android.intent.action.PACKAGE_ADDED")) {//这个判断条件是防止其他卸载时影响到本应用 if (context.getApplicationInfo().processName .equals("你的进程的名称")) { do the things that you wanted } } } };
注册监听,
IntentFilter intentFilter1 = new IntentFilter( "android.intent.action.PACKAGE_ADDED"); intentFilter1.addDataScheme("package"); this.registerReceiver(installedBr, intentFilter1);
卸载程序也一样
android.intent.action.PACKAGE_REMOVED这个action
intent.getDataString() 可以获取到安装或卸载的包名