我有問題了解上下文我編寫了一個程序來控制我的指示燈,但我需要檢查他是否沒有連接錯誤的WiFi,然後使用錯誤的IP。我嘗試多種選擇沒有一個好的解決方案。我期待了一些關於背景枯竭成功的問題。如果您需要完整的程序,我可以將它發送給你,但我認爲這是足夠的代碼:)Android Eclipse上下文無法解析返回類型
確切的問題是getCurrentSsid(上下文)錯誤:上下文無法在返回類型來解決
//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)
什麼問題? – 2014-09-22 15:16:16
對不起,我編輯了它。 – 2014-09-22 15:34:18
上下文變量設置在哪裏? O_o – 2014-09-22 15:37:52