Detect CONNECTIVITY CHANGE in Android 7 and above when app is killed/in background

后端 未结 5 1672
礼貌的吻别
礼貌的吻别 2020-11-27 12:56

Problem:

So the problem is that I have an app which sends a request to our backend whenever WiFi is connected (with the connected SSID and other inf

5条回答
  •  忘掉有多难
    2020-11-27 13:04

    Below is excerpt from documentation

    Apps targeting Android 7.0 (API level 24) and higher do not receive CONNECTIVITY_ACTION broadcasts if they declare the broadcast receiver in their manifest. Apps will still receive CONNECTIVITY_ACTION broadcasts if they register their BroadcastReceiver with Context.registerReceiver() and that context is still valid.

    So you will get this Broadcast till your context is valid in Android N & above by explicitly registering for same.

    Boot Completed:

    You can listen android.intent.action.BOOT_COMPLETED broadcast you will need this permission for same.

    
    

    App Killed Scenario:

    You are not going to receive it.

    That is very much expected and due to various reasons

    • Android Oreo has limitations on running services in background, so you may face this on O devices

    • Doze mode on Android Marshmallow onwards can cause this, it will stop all network operations itself & take away CPU wake locks

    • Though Doze mode have one mechanism for requesting whitelisting of apps, this might be useful for you.

提交回复
热议问题