0

I used a broadcast receiver to detect the wifi connection. it successfully works for the android Lolipop. but when I try to work with Pie(android 9) it is not working. I registered this broadcast in AndroidManifest.xml as follows.

 <receiver android:name=".ExampleBroadcast">
    <intent-filter>
       <action android:name="android.net.wifi.WIFI_STATE_CHANGED"/>
       <action android:name="android.net.conn.CONNECTIVITY_CHANGE" />
   </intent-filter>
 </receiver>

Example broadcast is my class which extended the broadcast receiver. it does works as follows.

package com.example.myapplication;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.net.wifi.WifiInfo;
import android.net.wifi.WifiManager;
import android.widget.Toast;

public class ExampleBroadcast extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
            //required task
    }
}

The above code works for the android 5 and not support for the android Pie. I want to know what is the correct registration criteria and what is the compatible action for the android.net.conn.CONNECTIVITY_CHANGE for above in android 7.

Hilton
  • 337
  • 6
  • 19
  • Check this : https://stackoverflow.com/questions/48527171/detect-connectivity-change-in-android-7-and-above-when-app-is-killed-in-backgrou – AskNilesh Dec 09 '19 at 10:03

1 Answers1

1

I know that in last versions of Android a lot of policies related to energy consumption and inter process communication have been changed; broadcast receivers have been changed too.

I find more usefull for you if you base your solution on a more consolidated answer like this one "How to Detect CONNECTIVITY_CHANGE", rather than on a newly written answer by me.

If the linked answer will not be usefull for you, I suggest to make a fast search on Google with keywords like for example "android pie connectivity change broadcast receiver" in order to find the best answer that suits your specific problem.