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.