We need the foreground service of our application to be restarted after the application is automatically updated from Google Play. For SDK < 26 we registered the receiver on PACKAGE_REPLACED actoin and everything worked fine. How can we do the same thing in SDK 26 if implicit intents are forbidden? Thanks.
First, not all implicit broadcasts are banned. There is a whitelist.
Second, ACTION_MY_PACKAGE_CHANGED
is an explicit broadcast, sent only to your app. Quoting the documentation:
Apps that target Android 8.0 or higher can no longer register broadcast receivers for implicit broadcasts in their manifest. An implicit broadcast is a broadcast that does not target that app specifically. For example, ACTION_PACKAGE_REPLACED is an implicit broadcast, since it is sent to all registered listeners, letting them know that some package on the device was replaced. However, ACTION_MY_PACKAGE_REPLACED is not an implicit broadcast, since it is sent only to the app whose package was replaced, no matter how many other apps have registered listeners for that broadcast.
So, you should be able to register for ACTION_MY_PACKAGE_REPLACED
, and restart your service there.