0

I have a list wifilist that contains access points informations: This is my list adapter class:

public ListAdapterWifi(Context context, List<ScanResult> wifiList) {
        this.context = context;
        this.wifiList = wifiList;
        inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);

    }

    @Override
    public int getCount() {
        return wifiList.size();
    }

    @Override
    public Object getItem(int position) {
        return null;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }


    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        Holder holder;
        System.out.println("viewpos" + position);
        View view = convertView;
        if (view == null) {
            view = inflater.inflate(R.layout.listeadapter, null);
            holder = new Holder();
            holder.tvDetails = (TextView) view.findViewById(R.id.tvDetails);

            view.setTag(holder);
        } else {
            holder = (Holder) view.getTag();
        }
        holder.tvDetails.setText("SSID :: " + wifiList.get(position).SSID
                + "\nForce du signal reçu :: " + wifiList.get(position).level
                + "\n@ mac du point d'accès :: " + wifiList.get(position).BSSID
                + "\nCanal :: "
                + convertFrequencyToChannel(wifiList.get(position).frequency)
                + "\nFréquence :: " + wifiList.get(position).frequency
                + "\nType de sécurité :: " + wifiList.get(position).capabilities);

        return view;
    }


    public static int convertFrequencyToChannel(int freq) {
        if (freq >= 2412 && freq <= 2484) {
            return (freq - 2412) / 5 + 1;
        } else if (freq >= 5170 && freq <= 5825) {
            return (freq - 5170) / 5 + 34;
        } else {
            return -1;
        }
    }

    class Holder {
        TextView tvDetails;

    }
}

And this is WifiMonitorActivity, the activity that display the list in a listview:

 public class WifiMonitorActivity extends Activity {
    private WifiManager mainWifi;
    private WifiReceiver receiverWifi;
    ListAdapterWifi adapter;
    ListView lvWifiDetails;
    List<ScanResult> wifiList;
    WifiManager wifi;



    double [] queryC = new double[3];


    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
     setContentView(R.layout.wifiresult );
     lvWifiDetails = (ListView) findViewById(R.id.lvWifiDetails);


     mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE);
     receiverWifi = new WifiReceiver();
     registerReceiver(receiverWifi, new IntentFilter(
     WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
     scanWifiList();
    }
    public double [] getRSS(double [] queryC){
        if(wifilist != null){

        for (int i=0; i<wifiList.size(); i++){
        switch (wifiList.get(i).BSSID){ 
          case "56:2f:27:43:4b:f5" : queryC [0]= + wifiList.get(i).level ; break; 
          case "20:16:e8:4f:55:e8": queryC [1]  = + wifiList.get(i).level ; break; 
          case "7c:e8:d3:31:7f:b9": queryC [2] =  + wifiList.get(i).level ; break; 
        }
         }  
}

        return queryC;
        }


    private void setAdapter() {
    adapter = new ListAdapterWifi(getApplicationContext(), wifiList);
    lvWifiDetails.setAdapter(adapter);
    }
    private void scanWifiList() {
    mainWifi.startScan();
    wifiList = mainWifi.getScanResults();
    setAdapter();
    }

    class WifiReceiver extends BroadcastReceiver {
        public void onReceive(Context c, Intent intent) {


        }
    }

    }

I want to extract BSSID corresponding to Access Points with specified SSID And put the 3 BSSID recuperated in the array queryC. then I want to recuperate the queryC in my knn class like this way:

WifiMonitorActivity w = new  WifiMonitorActivity();
        double [] query= w.getRSS(queryC);

the problem is that the queryC is not recuperated, should I use another list instead of wifiList? I'm confused.

Thank's in advance

N.InFOR
  • 15
  • 5
  • 1
    You almost got it. You need to check if `wifilist != null`. – shmosel Aug 26 '16 at 20:05
  • check wifilist != null not wifilist.size() != null because primitive types in Java cannot be null. Check this http://stackoverflow.com/questions/16124228/the-operator-is-undefined#answer-16124239 – Abu Yousuf Aug 26 '16 at 20:17
  • Where(in which class) you are calling getRSS(queryC) function. – Abu Yousuf Aug 26 '16 at 20:38
  • In another class called knn.java (k-nearest neighbor algorthim) – N.InFOR Aug 26 '16 at 20:46
  • Creating activity object this way is not recommended. Check this question and answer http://stackoverflow.com/questions/14956018/can-i-create-the-object-of-a-activity-in-other-class – Abu Yousuf Aug 26 '16 at 21:00
  • I tried that and there is new errors, maybe I did it wrongly: I declared: `static WifiMonitorActivity WifiMonitorActivity;` an then: `WifiMonitorActivity = this; public static WifiMonitorActivity getInstance() { return WifiMonitorActivity; }` but I have error just here saying: >Syntax error on token "WifiMonitorActivity", @ expected and when I changed the second class to this: `//WifiMonitorActivity w = new WifiMonitorActivity(); WifiMonitorActivity.getInstance().getRSS(queryC); //double [] query= w.getRSS(queryC);` – N.InFOR Aug 27 '16 at 10:59
  • I get this: >The method getInstance() is undefined for the type WifiMonitorActivity – N.InFOR Aug 27 '16 at 10:59

0 Answers0