有一些需求,在軟件卸載的時候做一些動作,但是我最近發現,在5.1上,覆蓋安裝的時候會發remove和replace兩種intent,這樣會導致功能異常,解決方案有2
- Intent.EXTRA_REPLACING
if (intent.getAction().equals(Intent.ACTION_PACKAGE_REMOVED)) {
String packageName = intent.getData().getSchemeSpecificPart();
boolean booleanReplacing = intent.getBooleanExtra(Intent.EXTRA_REPLACING, false);
LogUtils.e("booleanReplacing:" + booleanReplacing);
LogUtils.e("remove:" + packageName);
if (!booleanReplacing) {
//這裏是真正的卸載
}
}
2.監聽Intent.ACTION_PACKAGE_FULLY_REMOVED
這個廣播是應用被卸載,數據被時纔會發,所以,這是真正的被卸載的時候會發的。