PACKAGE_REMOVED & then PACKAGE_ADDED are fired along with PACKAGE_REPLACED Intent Action

蹲街弑〆低调 提交于 2019-12-18 10:35:47

问题


All I am trying to do is update my list on each Install & Uninstall but not on Package Replace .So the main problem is that Install & Uninstall intents are launched on each Replace action.

So For this I have implemented a BroadcastReciever as below

<receiver android:name =".IntentReceiverTest.AppReciever">
  <intent-filter>
         <action android:name="android.intent.action.PACKAGE_REMOVED"/>
         <action android:name="android.intent.action.PACKAGE_REPLACED"/>
         <action android:name="android.intent.action.PACKAGE_ADDED"/>
         <data android:scheme="package"/> 
  </intent-filter>
</receiver> 

On each Replace I get 3 broadcasts with actions

  • First with PACKAGE_REMOVED which fires AppReciever
  • then after PACKAGE_ADDED which again fires AppReciever
  • And then after few seconds PACKAGE_REPLACED which again fires AppReciever

So please suggest any better way to catch only Replace Action

Or

a way to stop previously launched Services due to PACKAGE_REMOVED and PACKAGE_ADDED action.


回答1:


Just check intent.getBooleanExtra(Intent.EXTRA_REPLACING, false):

if (!intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED) &&
    intent.getBooleanExtra(Intent.EXTRA_REPLACING, false))
    return;


来源:https://stackoverflow.com/questions/5217237/package-removed-then-package-added-are-fired-along-with-package-replaced-inten

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!