Android:仅通过 WIFI 发送数据 [英] Android: Send data only by WIFI

查看:32
本文介绍了Android:仅通过 WIFI 发送数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个在后台运行并向服务器发送数据的服务,我只想通过 wifi 而不是其他方式(gprs 或其他方式)发送这些数据,这可能吗?如果是,我怎样才能做到这一点?如果您有示例代码或链接,那就太好了.谢谢.

I have a service that runs in background and send data to a server, I want to send this data only by wifi and not another way (gprs or else) is that possible? and if it is, how can I achieve that? if you have sample codes or links that would be great. thank you.

推荐答案

final ConnectivityManager connMgr = (ConnectivityManager)
 this.getSystemService(Context.CONNECTIVITY_SERVICE);

final android.net.NetworkInfo wifi =
 connMgr.getNetworkInfo(ConnectivityManager.TYPE_WIFI);

NetworkInfo 结构应该具有 Wifi 子系统的连接状态.查看文档:

The NetworkInfo structure should have the connectivity state of the Wifi Subsystem. Look at the documentation:

http://developer.android.com/reference/android/net/网络信息.html

使用isConnected方法查看wifi是否连接.轻松点!

Use the isConnected method to see if wifi is connected. Easy Peasy!

这篇关于Android:仅通过 WIFI 发送数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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