如何强制的Andr​​oid通过Wi-Fi HTTP连接,而不是蜂窝? [英] How to force the HTTP connection over Wi-Fi instead of cellular in Android?

查看:116
本文介绍了如何强制的Andr​​oid通过Wi-Fi HTTP连接,而不是蜂窝?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序,以检测连接到Wi-Fi网络的设备是必要的一个,然后在火的Wi-Fi网络HTTP请求编程。我已搜查,但我没有找到任何方法或类,这将帮助我做到这一点。

My application has to detect that the device connected to the Wi-Fi network is the required one and then fire a HTTP request over that Wi-Fi network programmatically. I have searched, but I didn't find any method or class which will help me to do this.

我想禁用蜂窝网络,使HTTP请求将通过Wi-Fi网络,但即使在这我没有成功。
而且,我可以编程方式启用和禁用蜂窝和Wi-Fi网络?

I thought of disabling the cellular network so that the HTTP request will go through the Wi-Fi network but even in this I didn't have success. And also, can I enable and disable the cellular and Wi-Fi networks programatically?

推荐答案

有没有办法迫使它使用一个或另一个。无论网络可用时使用3G或Wi-Fi是否(如果Wi-Fi连接3G是关闭的)。如果你不希望基于上做一些网络目前正在使用中,你可以做一个检查Wi-Fi是否未连接,并且不会做一些动作,如果是这样的话,并提示用户。如果启用纬度谷歌地图做类似这样的东西。

There is no way to force it to use one or the other. Whatever network is available is used whether 3G or Wi-Fi (if Wi-Fi is connected 3G is off). If you don't want to do something based on which network is currently in use you can do a check whether Wi-Fi is not connected and don't do some action if that is the case, and prompt the user. Google Maps does something similar to this if Latitude is enabled.

借助 WifiManager 类有一堆的方法可能对你有用。

The WifiManager class has a bunch of methods that may be useful to you.

这篇关于如何强制的Andr​​oid通过Wi-Fi HTTP连接,而不是蜂窝?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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