Check if BroadcastReceiver is not blocked on startup [Android 6.0]

122 Views Asked by At

I have implemented code which checks if my BroadcastReceiver is not disabled to run on system startup. My intention is get information that my app is blocked by some external app and therefore cannot start (I will inform user that he needs to unblock otherwise my service won't work).

So far following part of code worked for me like a charm:

ComponentName componentName = new ComponentName(this, MyBootCompletedReceiver.class);
int state = getPackageManager().getComponentEnabledSetting(componentName);

if (state != PackageManager.COMPONENT_ENABLED_STATE_ENABLED && state != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT) {
 // ALERT that Receiver is blocked -> works for Android < 6.0
}

This code works on each Android version older than 6.0 and returns that component is disabled (COMPONENT_ENABLED_STATE_DISABLED) once I blocked my application by external tool (i.e. Startup Manager). My app didn't start on system boot what is exactly expected.

Above code doesn't work on Android 6.0+ (Galaxy S6). It always returns me that my Receiver is enabled (COMPONENT_ENABLED_STATE_ENABLED) if I follow the same test scenario.

Does someone meet such a problem?

Regards,

DM

0

There are 0 best solutions below