1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
public String [] hotspotscan()
{ if(this.getPackageManager().checkPermission("android.permission.ACCESS_WIFI_STATE", ctx.getPackageName()) == 0)
{
final String [] resultat= new String [5];
IntentFilter intf= new IntentFilter();
intf.addAction(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION);
registerReceiver( new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
WifiManager wifi = (WifiManager) getSystemService (Context.WIFI_SERVICE);
// Listes des hotspots qui se trouve a la porte de mobile.
List hotspot= wifi.getScanResults();
ScanResult msignal=null;
if(hotspot.isEmpty())
{
System.out.println("===Desole il n y a pas d hotspot : "+hotspot.size());
}
else System.out.println("===Le nombre de hotspot trouve est : "+hotspot.size());
// Recherche du hotspot dont le signal est le plus eleve
for (ScanResult result : hotspot) {
if (msignal == null ||
WifiManager.compareSignalLevel(msignal.level, result.level) < 0)
msignal = result;
}
resultat[0]= "L addresse du hotspot :"+ msignal.BSSID;
resultat[1]=" Le type d autentification :"+msignal.capabilities;
resultat[2]=" Le nom du reseaux : "+msignal.SSID;
resultat[3]="Niveau du signal :"+ msignal.level+" dBm";
resultat[4]="Frequence du signal :"+msignal.frequency+" Mhz";
}; },intf); wifi.startScan() ;
// Affichage dans logcat
for( String str : resultat)
{
System.out.println("==="+str);
}
return resultat;
}
else {
System.out.println("===Ajouter la permission! : ");
return null;
}
} |
Partager