簡體   English   中英

無法以返回類型解析Android Eclipse上下文

[英]Android Eclipse context cannot be resolved in return type

我在理解上下文時遇到問題,我編寫了一個控制燈光的程序,但是我需要檢查他是否沒有連接錯誤的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)

doInBackground context ,范圍內沒有帶名稱context符號。

Context傳遞給異步任務的一種常見方法是將其存儲在成員變量中,然后將其傳遞給構造函數arg:

private Context mContext;

public SendCommand(Context context) {
    mContext = context;
}

然后在需要Context地方使用mContext

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM