可用接入点的信号强度 [英] Signal strength of available access points

查看:96
本文介绍了可用接入点的信号强度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从所有可用的wifi接入点获取信号强度信息,但是它不起作用...它似乎总是返回一些空异常.我也尝试在移动设备上运行它,但无法正常工作.我已经指出了以粗体显示注释会造成错误的那一行.

I am trying to get the signal strength info from the all the available wifi access points but it doesnt work... Its always returning some null exception it seems. I tried to run it in mobile also but its not working. I have pointed out the line which is creating error by placing a comment in bold.

package a.c;

import java.util.ArrayList; 
import java.util.List;
 
import a.c.WifiActivity.WifiReceiver; 
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.widget.TextView; 
import android.widget.Toast; 
 
public class WifiActivity extends Activity { 
private WifiManager mainWifi; 
private WifiReceiver receiverWifi;
 
TextView sig;
 
/** Called when the activity is first created. */
 
@Override
 
public void onCreate(Bundle savedInstanceState) { 
super.onCreate(savedInstanceState); 
setContentView(R.layout.main); 
mainWifi = (WifiManager) getSystemService(Context.WIFI_SERVICE); 
receiverWifi = new WifiReceiver(); 
registerReceiver(receiverWifi, new IntentFilter(WifiManager.SCAN_RESULTS_AVAILABLE_ACTION)); 
}
 
class WifiReceiver extends BroadcastReceiver { 
public void onReceive(Context c, Intent intent) { 
List wifiList = mainWifi.getScanResults(); 
for (int i = 0; i < wifiList.size(); i++) { 
ScanResult scanResult = wifiList.get(i); 
// I have to put a try catch block here otherwise it returns an exception. 
try{ 
sig.append(scanResult.level+";"); 
} 
catch(exception e){}
}
} 
}
}



任何人都可以通过代码帮助我.我不知道该怎么做才能从访问点获得信号强度信息.附近有访问点,但我无法获得强度.如果有人可以提供代码或任何帮助,那我将非常感激.注意:我已经在清单中添加了访问wifistate的必要权限,因此那里不是问题.



Can anyone help me with the code. I dont know what to do to get the signal strength info from the access points.There are access points nearby but im not able get the strength.If anyone could provide the code or any help then i would be thankful. Note: I have added the required permission to access wifistate in the manifest also so its not a problem there.

推荐答案

我没有任何解决方案,但我了解到这里有很多东西,它确实有效..它很有帮助.

I don''t have any solution but i learned a lot of things here and it really works.. it helps a lot.

http://www.2012kiaoptima.com
http://www.adsonoahu.com


这篇关于可用接入点的信号强度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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