flutternetwork / WiFiFlutter

Flutter plugin suite for various WiFi services.
https://wifi.flutternetwork.dev
289 stars 182 forks source link

is there any way to disable captive portal page ? #120

Open vb-star opened 3 years ago

Niek commented 3 years ago

Same issue here. When manually connecting to the WiFi network, it works fine. When using connect()/findAndConnect(), all HTTP requests to internal IPs hang because of the captive portal check.

daadu commented 3 years ago

This should not happen since we call .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) which removes the requirement of the network to have internet.

@Niek I think we need to enforce the process to use this network, once conneted.

Can you add ConnectivityManager.setProcessDefaultNetwork(network); in onAvailable callback of networkCallback and test if the captive portal still comes?

daadu commented 3 years ago

in this case also need to ConnectivityManager.setProcessDefaultNetwork(null); in disconnect.

Niek commented 3 years ago

@daadu that worked! thanks!

Do you want me to make a PR?

daadu commented 3 years ago

Yes, please file the PR, make sure ConnectivityManager.setProcessDefaultNetwork(null); is called to clean up.

daadu commented 3 years ago

ConnectivityManager.setProcessDefaultNetwork is deprecated and therefore not reliable.

Use connManger.bindProcessToNetwork instead.

daadu commented 3 years ago

Infact this is what forceWifiUsage does.

I think the "captive portal" wont come if you call that after connect.

daadu commented 3 years ago

But I think we should this internally, we have got lot of issues stating the same, after connect, the network does not work, I ask them to call forceWifiUsage explicitly.

Niek commented 3 years ago

Ahhhh.... this works indeed:

await WiFiForIoTPlugin.forceWifiUsage(true);

So there's no need for a PR... maybe this should be documented somewhere though.

vb-star commented 3 years ago

can you please check it with android 9 also?

one more thing, whether you add .removeCapability(NetworkCapabilities.NET_CAPABILITY_INTERNET) then is your internet is working out of the application in Android 10 onward?

Niek commented 3 years ago

Yes, internet outside of the app is working with withInternet: false.

But it seems that once I disconnect from the SSID (for example back to the original SSID) I don't have internet anymore in the app. Outside the app it works fine - this is maybe related to #130.

vb-star commented 3 years ago

whenever I tried it with my open wifi, yes I have connected to that open wifi but my internet is not working out of the application. is there any specific reason?

daadu commented 3 years ago

According to the docs the network connected, will only work with the application.

So will not have effect outside the app.

daadu commented 3 years ago

Ahhhh.... this works indeed:

await WiFiForIoTPlugin.forceWifiUsage(true);

So there's no need for a PR... maybe this should be documented somewhere though.

I suggest, this should happen out of the box, instead of documenting it somewhere.

vb-star commented 3 years ago

I aware of that, I am also using this but My internet is not working out of the Application. yes, it's working only inner app.

daadu commented 3 years ago

Yes, internet outside of the app is working with withInternet: false.

But it seems that once I disconnect from the SSID (for example back to the original SSID) I don't have internet anymore in the app. Outside the app it works fine - this is maybe related to #130.

This is because with enabling forceWifiUsage (internally bindNetwork), you need to make sure the bind is removed (properly cleaned up) with disabling it.

This is mandatory (to disable) according to docs, disconnecting will not release the bind.

vb-star commented 3 years ago

is there any method for remove binding?

daadu commented 3 years ago

is there any method for remove binding?

forceWifiUsage(false)

vb-star commented 3 years ago

oh.. sorry, Let me check with this.

Actually, I have done it with some modification in deprecate code and It's working well. My internet is working out of the application in Android 10 onward.