1

My application has a PackageUpdatedReceiver which is registered through the manifest file.

With what I understood from Broadcast Limitations (https://developer.android.com/about/versions/oreo/background.html#broadcasts) for Oreo, I did something like this:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
    registerBroadcastReceiver();
}

private void registerBroadcastReceiver() 
{
    IntentFilter mIntentFilter = new IntentFilter();
    mIntentFilter.addAction(Intent.ACTION_PACKAGE_ADDED);
    mIntentFilter.addAction(Intent.ACTION_PACKAGE_REPLACED);
    mIntentFilter.addAction(Intent.ACTION_PACKAGE_FULLY_REMOVED);
    mContext.registerReceiver(new PackageUpdatedReceiver(), mIntentFilter);
}

but it's not working.

Also, I don't understand how will registry of a broadcast receiver over app context persist when the app has been killed?

Komal12
  • 3,340
  • 4
  • 16
  • 25
Devanshu
  • 19
  • 1
  • create a local broadcast and use it – Quick learner Mar 19 '18 at 05:58
  • "how will registry of a broadcast receiver over app context persist when the app has been killed?" - It won't. That's part of the reason for the new restrictions; so apps aren't running for every possible broadcast. That may also be why your current code isn't working. Are you sure that registering `Context` is alive when those broadcasts happen? – Mike M. Mar 19 '18 at 06:05
  • @MikeM. yes mate, mContext is the parent activity which is alive as long as the application is in memory. – Devanshu Mar 19 '18 at 06:39
  • How are they expecting apps to be in sync with the system w.r.t. some of the implicit broadcasts. For instance my app keeps track of all apps installed on the device. Are they expecting me to sync up every time I launch the app? – Devanshu Mar 19 '18 at 06:41
  • Yep, pretty much. https://stackoverflow.com/a/46489255 – Mike M. Mar 19 '18 at 07:03

0 Answers0