android系统自带了apk安装成功后会发出一个广播,那么我们在activity上进行注册广播即可
@Override
protected void onStart() {
super.onStart();
IntentFilter intentFilter = new IntentFilter();
intentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
intentFilter.addDataScheme("package");
// 注册一个广播
registerReceiver(mBroadcastReceiver, intentFilter);
}
@Override
protected void onStop() {
// 解除广播
unregisterReceiver(mBroadcastReceiver);
super.onDestroy();
}
// 接收到安装完成apk的广播
private BroadcastReceiver mBroadcastReceiver= new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
mVersionListAdapter.notifyDataSetChanged();//listview适配器进行刷新,读者可自己按照自己的需要进行更改自己的功能
}
};