【发布时间】:2014-09-22 15:10:46
【问题描述】:
我理解有问题上下文我写了一个程序来控制我的灯,但是我需要检查他是否没有连接错误的WiFi然后使用错误的IP。我尝试了多种选择,但没有一个好的解决方案。我看一些关于上下文白化成功的早期问题。如果你需要完整的程序,我可以发给你,但我认为这已经足够了:)
确切的问题是 getCurrentSsid(context) 错误:上下文无法在返回类型中解析
//CLASS SENDCOMMAND
public class SendCommand extends AsyncTask<String, Integer, JSONArray> {
static boolean WifiSSID;
public SendCommand(boolean wifi) {
this.wifi = wifi;
}
//FUNCTION TO CHECK THE CURREN SSID
public boolean getCurrentSsid(Context context) {
ssid = null;
ConnectivityManager connManager = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE);
NetworkInfo networkInfo = connManager.getNetworkInfo(ConnectivityManager.TYPE_WIFI);
if (networkInfo.isConnected()) {
final WifiManager wifiManager = (WifiManager) context.getSystemService(Context.WIFI_SERVICE);
final WifiInfo connectionInfo = wifiManager.getConnectionInfo();
if (connectionInfo != null && !TextUtils.isEmpty(connectionInfo.getSSID())) {
ssid = connectionInfo.getSSID();
}
}
if (ssid =="Room#2")
return true;
else
return false;
}
//wifiSSID = boolean getCurrentSsid(context);
//send the command
@Override
protected JSONArray doInBackground(String... params) {
// TODO Auto-generated method stub
Log.d(tag, "Beginnen do in background");
Log.d(tag, "Wifi is " + wifi);
HttpClient client = new DefaultHttpClient();
HttpGet get;
if (wifi && **getCurrentSsid(context)**){ //HERE HE GIVES A ERROR getCurrentSsid(context)
【问题讨论】:
-
对不起,我编辑了它。
-
上下文变量在哪里设置? O_o
标签: java android eclipse class