For API level 12 & above
Just register the broadcast receiver to receive the call only after updating the application package .
public class PackageUpdateReceiver extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) {
Be sure to register the broadcast receiver in the manifest!
<receiver android:name=".receivers.PackageUpdateReceiver"> <intent-filter> <action android:name="android.intent.action.MY_PACKAGE_REPLACED" /> </intent-filter> </receiver>
Now for the API level & lt; 12
You must register to receive the universal package update recipient by replacing the action name in the manifest as shown below.
MY_PACKAGE_REPLACED with PACKAGE_REPLACED
And in the onReceive () method of BroadcastReceiver, check if it is the name of your application package,
if (intent.getDataString().contains("com.your.app")){ ... }
source share