1

我有一部在 Page Plus 上使用的安卓手机。我正在尝试找出远程检测(从 linux 网络服务器)设备是否连接到 wifi 网络的最佳方法。

我想在未连接到 wifi 时禁用我的谷歌语音帐户上的短信转发,但由于我的手机没有数据连接,因此必须远程触发。我知道如何编写转发设置切换功能,我只需要远程检测android设备的wifi状态。

我提出了一些想法,比如监控手机的 gtalk 状态,以及检测 android 客户端是否在线——我可以让它工作,但这不是世界上最干净的方法。

有什么建议或想法吗?我知道这不完全是一个编程问题,但我希望得到一些帮助!

4

1 回答 1

1

You could run a background service on the Android client which pings the webserver at constant time intervals whenever wifi is connected - whenever the client misses a "scheduled" check-in, the webserver concludes that the phone is disconnected, and executes whatever actions you want in that case.

To ping the server, I would use a simple TCP socket:

// you could use IP address instead of the hostname if you don't have a domain name
// PORT_NUM is some value shared between the server and the client e.g. 3456
Socket sock = new Socket("mywebserverurl.com", PORT_NUM);
OutputStream out = sock.getOutputStream();
String data = getDataServerNeeds();
out.write(data.getBytes());
sock.close();

This tutorial has a more detailed example, including the server-side aspect.

于 2012-04-11T15:08:53.583 回答