无线扫描显示没有结果还是慢proccess [英] wifi scanner shows no result or slow proccess

查看:173
本文介绍了无线扫描显示没有结果还是慢proccess的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我写了一个应用程序捕获的WiFi接入点的信息。我不明白为什么有些时候它扫描不具备而当我关闭,并在手机设置,我可以看到所有的接入点存在了WiFi的任何结果。
更过有没有办法让无线扫描的结果更快?在手机设置了WiFi转弯时像什么手机确实。我提出了具体的名为UMCH_Network接入点的结果
谢谢

I wrote an application to capture the wifi access points info. I do not understand why some times it scanning do not have any result while when I turn off and on the wifi in the phone settings I can observe all of the access points there. more over is there any way to get the result of wifi scanning faster?! like what the phone does when turning on the wifi in the phone settings. I made the result specific for an access point called "UMCH_Network" thanks

这是我的.java文件内容:

this is my .java file content:

package com.example.wps;

import java.util.List;

import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.wifi.ScanResult;
import android.net.wifi.WifiManager;
import android.os.Bundle;
import android.os.Handler;
import android.view.Menu;
import android.view.MotionEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;


public class MainActivity extends Activity {

TextView mainText;
TextView notifText;
EditText eTxtnumberOfTimes;
EditText eTxtDistance;

WifiManager wifiManager;
WifiReceiver wifiReceiver;
List<ScanResult> wifiList;
StringBuilder sb = new StringBuilder();
Handler handler = new Handler();
String DirectoryName;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    notifText = (TextView) findViewById(R.id.txvMain);
    wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
}

public void ScanAndDraw(View v) {
    scanwifi();
}

public void scanwifi() {
    wifiReceiver = new WifiReceiver();
    registerReceiver(wifiReceiver, new IntentFilter(
            WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    notifText.setText("Scanning ...");
    wifiManager.startScan();
}

class WifiReceiver extends BroadcastReceiver {
    public void onReceive(Context c, Intent intent) {
        sb = new StringBuilder();
        wifiList = wifiManager.getScanResults();
        for (ScanResult result : wifiList) {
            if (result.SSID.equals("UMCH_Network")) {
                sb.append("Distance: " + eTxtDistance.getText().toString()
                        + "\t");
                sb.append("Number of Times: "
                        + eTxtnumberOfTimes.getText().toString() + "\t");
                sb.append("Level:\t" + result.level + "\t");
                // n=4.48 d0=3meter
                sb.append("estimated distance in meter: "
                        + (3 * (Math.pow(10, (-result.level - 46) / 44.8)))
                        + "\n");
            }
            notifText.setText(sb);
        }

        //mainText.setText(sb);
        notifText.setText("");
    }
}

public boolean onCreateOptionsMenu(Menu menu) {
    menu.add(0, 0, 0, "Refresh");
    return super.onCreateOptionsMenu(menu);
}

protected void onPause() {
    unregisterReceiver(wifiReceiver);
    super.onPause();
}

protected void onResume() {
    registerReceiver(wifiReceiver, new IntentFilter(
            WifiManager.SCAN_RESULTS_AVAILABLE_ACTION));
    super.onResume();
}

public boolean onTouch(View v, MotionEvent mo) {
    // float x = mo.getX();
    return false;
}
}

这是清单文件的内容:

and this is the content of manifest file:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.wps"
android:versionCode="1"
android:versionName="1.0" >

<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE"></uses-permission>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"></uses-permission>
<uses-permission android:name="android.permission.CHANGE_NETWORK_STATE"></uses-permission>

<uses-sdk android:minSdkVersion="3" android:targetSdkVersion="18" />

<application
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >
    <activity
        android:name="com.example.wps.MainActivity"
        android:label="@string/app_name" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
</application>

推荐答案

您可以立即显示最近使用这个code扫描无线网络的列表,

You can instantly show a list of wifi recently scanned by using this code,

WifiManager wifiManager = (WifiManager) getSystemService(Context.WIFI_SERVICE);
        List<ScanResult> apList = wifiManager.getScanResults();

这篇关于无线扫描显示没有结果还是慢proccess的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆