Question

I want to perform certain network actions when a specific wifi network is connected, and this has to be done automatically without user input even since boot time. There is also a Preference that tells me whether or not these actions are performed automatically.

As far as I have understood, applications need the special permission named RECEIVE_BOOT_COMPLETED to perform certain actions at boot time (including initializing the application itself), and those are implemented in the code via a BroadcastReceiver.

In order to save battery avoiding polling for wifi state, I can register a BroadcastReceiver for the ConnectivityManager.CONNECTIVITY_ACTION and query it for the wifi network's name.

Can the CONNECTIVITY_ACTION listener, or just any other listener, be declared from AndroidManifest.xml and be triggered without application start, just like making boot receiver useless?

Was it helpful?

Solution

AFAIK, you can respond to CONNECTIVITY_ACTION via a manifest-registered receiver. There are a few broadcasts where you cannot (e.g., ACTION_BATTERY_CHANGED). This would eliminate your need to get control at boot time.

You can enable and disable that receiver based on the preference, so you do not get control when it is not needed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top