Intercept cancel button press on ConnectivityManger requestNetwork new dialog, API 29

570 views Asked by At

I'm using the ConnectivityManger's requestNetwork API to programmatically connect to a specific network specified by a NetworkRequest object provided as first parameter. I also provide a NetworkCallback to receive notifications related to the status of the request.

Starting from API 29, the OS is showing a Dialog (NetworkRequestDialogFragment) where the user can select a network from the list or cancel the action.

According to the documentation, the NetworkCallback's onUnavailable method is invoked when the user clicks on the dialog's cancel button but also in case of connection failure.

Is there any advanced mechanisms to distinguish between these two scenarios?

1

There are 1 answers

0
Iván Garza Bermea On

onUnavailable() is only called in two scenarios:

  1. The user manually cancels the request
  2. The second case requires you to use a timeout within your request. If that's the case, running out of time will trigger onUnavailable() as well.

As for your questions, I don't think there's either a way of intercepting neither this Dialog or the second Dialog you get once onUnavailable() is triggered stating that there was an error -- I've been looking all over the place for something like this too. :/