1

I am developing an Android Xamarin Forms app which connects to a wifi programmatically.

I used ConnectivityManager and NetworkCallback classes to achieve this. Everything works fine, I can connect to the wifi successfully, pressing the "Connect" (Connetti) button of the dialog shown below.

enter image description here

Sometimes the required network is not detected and, a after a certain interval of seconds, it is shown another dialog. See below.

enter image description here

If the user taps on the "Cancel" (Cancella) button of this second dialog, the OnUnavailable method of the NetworkCallback is never called and I am not able to detect when the user chooses to dismiss it.

Anyone knows how to intercept the cancel tap of this second dialog?

giani.sim
  • 257
  • 2
  • 16
  • OnUnavailable is triggered by the System, not the app therefore if you want to capture when the user presses the cancel button in an app, you should have events tied to that particular app and not ConnectivityManager. – Always Learning Mar 30 '21 at 16:35
  • The two images attached are dialogs shown by the System, not by the app. I monitor OnAvailable, OnUnavailable, ecc.. with a NetworkCallback. But when i press "Cancel" on the second dialogs the OnUnavailable method is not called – giani.sim Mar 30 '21 at 16:40
  • 1
    Got it, let me add some more context. OnUnavailable is triggered by the system when a network can't be found for whatever reason (including timeout). This system dialog is decoupled from that flow in ConnectivityService. I.e., there is no connection between clicking cancel in this dialog and when OnUnavailable will be triggered therefore attempting to listen for OnUnavailable as related to this dialog won't work. – Always Learning Mar 30 '21 at 16:52
  • Clear. So there is no way to listen the click of the cancel button of the second dialog? – giani.sim Mar 30 '21 at 16:57
  • It looks like this would work: `WifiManager.registerNetworkRequestMatchCallback()`. Can you give that a shot? The specific event you would want is `INetworkRequestMatchCallback.onUserSelectionConnectFailure`. That is what ultimately filters to that dialog but it's a couple layers deep. If it works, I'll update with an answer. – Always Learning Mar 30 '21 at 18:52
  • One note, this API uses a signature permission NETWORK_SETTINGS which you probably won't have access to therefore it probably won't work. On that note, I didn't see anything you could listen on for when this happens. – Always Learning Mar 30 '21 at 19:03

0 Answers0