Android 覆蓋安裝會同時發送remove和replace的解決方案

有一些需求,在軟件卸載的時候做一些動作,但是我最近發現,在5.1上,覆蓋安裝的時候會發remove和replace兩種intent,這樣會導致功能異常,解決方案有2

  1. 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
這個廣播是應用被卸載,數據被時纔會發,所以,這是真正的被卸載的時候會發的。

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章