根据https://developer.android.com/topic/performance/background-optimization的提示，api level 24以后通过manifest注册的CONNECTIVITY_ACTION 将不再发送广播，解决方法是通过actity的oncreate方法注册
MyReceiver receiver=new MyReceiver(); IntentFilter filter=new IntentFilter(); filter.addAction(ConnectivityManager.CONNECTIVITY_ACTION); this.registerReceiver(receiver,filter);
Background processes can be memory- and battery-intensive. For example, an implicit broadcast may start many background processes that have registered to listen for it, even if those processes may not do much work. This can have a substantial impact on both device performance and user experience.
To alleviate this issue, Android 7.0 (API level 24) applies the following restrictions:
Apps targeting Android 7.0 (API level 24) and higher do not receive CONNECTIVITY_ACTION broadcasts if they declare their broadcast receiver in the manifest. Apps will still receive CONNECTIVITY_ACTION broadcasts if they register their BroadcastReceiver with Context.registerReceiver() and that context is still valid.
If your app uses any of these intents, you should remove dependencies on them as soon as possible so that you can properly target devices running Android 7.0 or higher. The Android framework provides several solutions to mitigate the need for these implicit broadcasts. For example, JobScheduler and the new WorkManager provide robust mechanisms to schedule network operations when specified conditions, such as a connection to an unmetered network, are met. You can now also use JobScheduler to react to changes to content providers. JobInfo objects encapsulate the parameters that JobScheduler uses to schedule your job. When the conditions of the job are met, the system executes this job on your app’s JobService.
In this document, we will learn how to use alternative methods, such as JobScheduler, to adapt your app to these new restrictions.