android监听应用安装,如判断是新安装的应用,还是覆盖安装的应用?
直接看代码:
public void onReceive(Context context, Intent intent) {
if (intent.getAction().equals(Intent.ACTION_PACKAGE_ADDED)) { // install
String packageName = intent.getDataString();
packageName = filterPackage(packageName);
Log.i(TAG, "install:" + packageName);
boolean isReplacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING,false);
int uid = intent.getIntExtra(Intent.EXTRA_UID,0);
Log.i(TAG, "install: isReplacing = " + isReplacing);
Log.i(TAG, "install: uid = " + uid);
if(!isReplacing){
//全新安装
}
}
}