获取无线网络强制网络门户资讯 [英] Get WiFi captive portal info

查看:176
本文介绍了获取无线网络强制网络门户资讯的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有访问Android的广播,该无线连接是目前一个强制网络门户的方式(需要网络登录)? Android的,似乎确实有这个内置的。如果没有一个广播接收器,有没有办法来检查圈养门户检查的结果?我相信这是使用这个类,这是从API隐藏的:

Is there a way to access Android's broadcast that the WiFi connection is currently a captive portal (requires web login)? Android seems to do have this built in. If not a broadcast receiver, is there a way to check for the result of the captive portal check? I believe it's using this class, which is hidden from the API:

<一个href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/5.L_$p$pview/android/net/CaptivePortalTracker.java\" rel=\"nofollow\">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/5.L_$p$pview/android/net/CaptivePortalTracker.java

在4.2之前,它可能使用:

Prior to 4.2, it was probably using:

<一个href=\"http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.1.2_r1/android/net/wifi/WifiWatchdogStateMachine.java\" rel=\"nofollow\">http://grep$c$c.com/file/repository.grep$c$c.com/java/ext/com.google.android/android/4.1.2_r1/android/net/wifi/WifiWatchdogStateMachine.java

背景:

我一直用我自己的方法来检测是否无线网络可能需要登录。我会等待一个无线连接的状态,然后ping一个网站,并确保有一个回应。这似乎工作在大多数情况下大。另一种策略是做的Htt prequest并为您重定向或收到回响应体,类似于Android在上面列出的类的策略。

I had been using my own method to detect whether WiFi likely required a login. I would wait for a WiFi connected state, then ping a site and make sure there was a response. This seemed to work great in most cases. Another strategy is to do a HttpRequest and check for a redirect or the response body you receive back, similar to Android's strategy in the classes listed above.

然而,新的棒棒糖是,当无线网络没有连接的移动数据连接使用。这意味着我的平方法仍然会返回结果,并且重新导向不会发生,因为该请求将通过移动数据进行路由。

However, new to Lollipop is that the mobile data connection is used when WiFi does not have connectivity. This means my ping method will still return results, and that a redirect would not happen, as the request would be routed over the mobile data.

有没有办法让Android的电流的WiFi强制网络门户的地位?如果没有,我们可以确保请求越过无线网络,即使没有通过Android作为连接见过?

Is there a way to get Android's current status of a WiFi captive portal? If not, can we make sure a request goes over WiFi even when there's no connectivity as seen by Android?

推荐答案

您不得不使用新的 ConnectivityManager.setProcessDefaultNetwork API强迫你的应用在通信强制网络门户。见的https://github.com/pawitp/muwifi-autologin/commit/f045fe36f1fd98a106ea652e2d56f7ddfc871760一个例子。

You'd have to use the new ConnectivityManager.setProcessDefaultNetwork API to force your app to communicate over the captive portal. See https://github.com/pawitp/muwifi-autologin/commit/f045fe36f1fd98a106ea652e2d56f7ddfc871760 for an example.

完成code补充说:

final ConnectivityManager cm = (ConnectivityManager) getSystemService(Context.CONNECTIVITY_SERVICE);
                        for (Network net : cm.getAllNetworks()) {
                            if (cm.getNetworkInfo(net).getType() == ConnectivityManager.TYPE_WIFI) {
                                Utils.logDebug(TAG, "Seting process network to " + net);
                                ConnectivityManager.setProcessDefaultNetwork(net);
                            }
                        }

这篇关于获取无线网络强制网络门户资讯的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆