Android 覆蓋安裝會同時傳送remove和replace的解決方案
有一些需求,在軟體解除安裝的時候做一些動作,但是我最近發現,在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
這個廣播是應用被解除安裝,資料被時才會發,所以,這是真正的被解除安裝的時候會發的。