Android: Send data only by WIFI

不羁的心 提交于 2019-12-08 09:37:29

问题


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.


回答1:


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

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

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

http://developer.android.com/reference/android/net/NetworkInfo.html

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




回答2:


Detect network connection type on Android

This post might be what you're looking for, you can check to see if your app is connected to wifi before sending any data. Hope this helps




回答3:


try looking at this: http://developer.android.com/training/efficient-downloads/connectivity_patterns.html#WiFi i think you'll find your answer there



来源:https://stackoverflow.com/questions/11742894/android-send-data-only-by-wifi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!