我要做的就是更新每个Install&Uninstall上的列表,但更新Package Replace上的而不是。因此,主要问题是在每个Replace操作上启动了Install&Uninstall意图。
所以
为此,我实现了如下的BroadcastReciever
<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>
每次替换时,我都会收到3个带有 Action 的广播
因此,请提出任何更好的方法来仅捕获“替换操作”
要么
由于PACKAGE_REMOVED和PACKAGE_ADDED 操作,一种停止先前启动的服务的方法。
最佳答案
只需检查intent.getBooleanExtra(Intent.EXTRA_REPLACING, false)
:
if (!intent.getAction().equals(Intent.ACTION_PACKAGE_REPLACED) &&
intent.getBooleanExtra(Intent.EXTRA_REPLACING, false))
return;