I am building a wifiP2P simple chatting application and in the android documentation (https://developer.android.com/training/connect-devices-wirelessly/wifi-direct) it syas that
WIFI_P2P_CONNECTION_CHANGED_ACTION Indicates the state of Wi-Fi P2P connectivity has changed. Starting with Android 10, this is not sticky. If your app has relied on receiving these broadcasts at registration because they had been sticky, use the appropriate get method at initialization to obtain the information instead.
now i am facing a problem with my application becuase when i test my app on any android 10 device or higher it doesn't respond to this Intent becuase they changed it. how can i modify my code so i can catch these intents and obtain this informaion. it says use "the appropriate get method at initializing " i do not know how or what should i use
in my main activity this is the connectionInfoListener code :
WifiP2pManager.ConnectionInfoListener mConnectionInfoListener = new WifiP2pManager.ConnectionInfoListener() {
@Override
public void onConnectionInfoAvailable(WifiP2pInfo info) {
final InetAddress groupOwnerAddress = info.groupOwnerAddress;
if (info.groupFormed && info.isGroupOwner) {
isHost = true;
status.setText("Host");
status.setTextColor(Color.parseColor("#a4c639"));
Log.d(TAG, "onConnectionInfoAvailable: this device is the HOST in the wifiDirect group");
server = new server();
server.start();
} else if (info.groupFormed) {
isHost = false;
status.setText("Client");
status.setTextColor(Color.parseColor("#a4c639"));
Log.d(TAG, "onConnectionInfoAvailable: this device is the CLIENT in the wifiDirect group");
client = new client(groupOwnerAddress);
client.start();
}
}
};
and this is my WiFiBroadcastReceiver code:
else if (WifiP2pManager.WIFI_P2P_CONNECTION_CHANGED_ACTION.equals(action)) {
// Connection state changed! We should probably do something about that
if(manager != null){
NetworkInfo mNetworkInfo = intent.getParcelableExtra(WifiP2pManager.EXTRA_NETWORK_INFO);
if (mNetworkInfo.isConnected()){
manager.requestConnectionInfo(channel,mainActivity.mConnectionInfoListener);
}else {
mainActivity.status.setText("Device Disconnected");
Log.d(TAG, "onReceive: connection ended. device disconnected ");
}
}