2015-04-17 153 views
0

我已經提出了一個應用程序來獲取和顯示相關的wifi信息,刪除重複的SSID並通過信號強度(更高的RSSI優先)顯示它們,計算每個AP的近似距離,我想知道是否有方法顯示我的RSSI在帶有顏色代碼的條形圖上(如Wifi Manager App)。我在ListView中顯示所有內容。這是我的代碼。在Android中顯示WiFi信號強度(顯示條)

public void onReceive(Context c, Intent intent) { 


     //////////////////// Inicializacion de variables ///////////////////// 
     final ImageView fondo=(ImageView)findViewById(R.id.fondo); 
     ListaWifi = ObjWifi.getScanResults(); 
     rssi = new int[ListaWifi.size()]; 
     wifisaux = new String[ListaWifi.size()]; 
     wifis = new String[ListaWifi.size()]; 
     BSSID=new String[ListaWifi.size()]; 
     tam = ListaWifi.size(); 
     ///////////////// Creacion de Lista de AP ///////////////////////// 
     for (int i = 0; i <tam; i++) { 

      ////////// Asignacion de canales de acuerdo a frec ///////// 
      switch (ListaWifi.get(i).frequency) { 
       case 2412: 
        canal = 1; 
        break; 
       case 2417: 
        canal = 2; 
        break; 
       case 2422: 
        canal = 3; 
        break; 
       case 2427: 
        canal = 4; 
        break; 
       case 2432: 
        canal = 5; 
        break; 
       case 2437: 
        canal = 6; 
        break; 
       case 2442: 
        canal = 7; 
        break; 
       case 2447: 
        canal = 8; 
        break; 
       case 2452: 
        canal = 9; 
        break; 
       case 2457: 
        canal = 10; 
        break; 
       case 2462: 
        canal = 11; 
        break; 
      } 
      //////////Calculo de la distancia /////////////////// 

      dist = Math.pow(10, (-(-26) - (ListaWifi.get(i).level))/(10 * 21.54)); 

      /////////////Agregacion de valores en la lista //////////////// 
      BSSID[i]=ListaWifi.get(i).BSSID; 
      rssi[i] = ListaWifi.get(i).level; 
      nombre=BSSID[0]; 
      wifisaux[i] = (("AP " + (i + 1) + "\n" + "SSID: " + ListaWifi.get(i).SSID + "\n BSSID: " + ListaWifi.get(i).BSSID + "\n Canal: " + canal + "\n RSSI: " + rssi[i] + "dBm" + "\n Distancia: " + dist + " m").toString()); 

     } 

     ///////////////Ordenamiento de AP de acuerdo a potencia///////Ordering list (higher RSSI first)/////// 
     for (int i = 0; i < tam-1; i++) { 
      if (rssi[i] > rssi[i+1]) { 
      }else{ 
       mascerca = wifisaux[i]; 
       wifisaux[i] = wifisaux[i+1]; 
       wifisaux[i+1] = mascerca; 
       auxbssid=BSSID[i]; 
       BSSID[i]=BSSID[i+1]; 
       BSSID[i+1]=auxbssid; 
      } 
     } 
     //////////////Eliminacion de redundancias//////Deleting duplicate SSIDs///////////////////// 
     for (int i=0;i<tam;i++){ 
      for (int j = 1; j < tam; j++) { 
       if (BSSID[i].equals(BSSID[j])){ 
        wifisaux[i]=wifisaux[j]; 
        BSSID[i]=BSSID[j]; 
       } 
      } 
      wifis[i] = wifisaux[i]; 
     } 


     ////////////Cambio de imagenes /////////////////////////////// 
     nombre=BSSID[0]; 
     if (nombre.equals(nombre2)){ 

     } 
     else { 
      final String str="img_"+(rnd.nextInt(6)+1); 
      fondo.setImageDrawable(getResources().getDrawable(getResourceID(str, "drawable",getApplicationContext()))); 
     } 
     nombre2=BSSID[0]; 

     /////////////Traslado de variables a Lista ////////Show everything in a list////////////// 
     list.setAdapter(new ArrayAdapter<String>(getApplicationContext(), android.R.layout.simple_list_item_1, wifis)); 
    } 

回答

0

我也很想知道如何在無線信號中顯示圖標。

您可以更改:

////////// Asignacion de canales de acuerdo a frec ///////// 
     switch (ListaWifi.get(i).frequency) { 
      case 2412: 
       canal = 1; 
       break; 
      case 2417: 
       canal = 2; 
       break; 
      case 2422: 
       canal = 3; 
       break; 
      case 2427: 
       canal = 4; 
       break; 
      case 2432: 
       canal = 5; 
       break; 
      case 2437: 
       canal = 6; 
       break; 
      case 2442: 
       canal = 7; 
       break; 
      case 2447: 
       canal = 8; 
       break; 
      case 2452: 
       canal = 9; 
       break; 
      case 2457: 
       canal = 10; 
       break; 
      case 2462: 
       canal = 11; 
       break; 
     } 

到:

in freq = ListaWifi.get(i).frequency; 
    canal = (freq == 2484) ? 14 : ((freq -2407)/5);