我正在使用以下代码检查网络连接:
public static boolean haveInternet(Context ctx)
{
NetworkInfo info = (NetworkInfo) ((ConnectivityManager) ctx.getSystemService(Context.CONNECTIVITY_SERVICE)).getActiveNetworkInfo();
if (info == null || !info.isConnected()) {
return false; // no connection
}
return true; // true if having connection
}
现在,在“无连接”上,我使用以下代码启动“无线设置”对话框:
context.startActivity(new Intent(Settings.ACTION_WIRELESS_SETTINGS));
在这里,用户可以“打开/关闭”无线网络,
现在,我如何才能知道用户是否“打开”了Wi-Fi?即上述无线连接成功的意图返回的结果。如何检查?
我想我需要调用StartActivityForResult方法,但不知道该怎么做?
更新:
我想用同样的方法
http://groups.google.is/group/android-developers/msg/6874a5e4675dffdb