0

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

yale
  • 31
  • 3
  • I think it is not possible. Read [here](http://stackoverflow.com/questions/17700542/how-to-determine-if-the-android-application-was-force-closed) and [here](http://stackoverflow.com/questions/16013578/how-to-detect-if-android-app-is-force-stopped-or-uninstalled). Back in the day you could check if the process was running usinc `ActivityManager`, but as of API 21 info of other applications is not available for privacy reasons (aka preventing fingerprinting based on installed apps) – Mister Smith Dec 16 '16 at 13:16
  • Is it possible that the application is in the "stopped state" (as it would be if you force stopped it)? In that situation, the `BroadcastReceiver` component is enabled, but it will not get called because the application is in the stopped state. You can check if the app is in the stopped state by calling `PackageManager.getApplicationInfo()` and check if `FLAG_STOPPED` is set in the `flags` member variable. – David Wasser Dec 16 '16 at 16:10

0 Answers0