来源:毕业设计
关键词:wifi数据的采集 SQLite数据库的使用
采集实验室内各坐标处各wifi信号的强度
//获取WifiManager实例
mWifiManager = (WifiManager) this.getSystemService(Context.WIFI_SERVICE);
//打开Wifi
if(!mWifiManager.isWifiEnabled()) {
mWifiManager.setWifiEnabled(true);
}
//ScanResult : 扫描到的wifi热点的数据集实体类.
List<ScanResult> scanResults = mWifiManager.getScanResults();
需要采集的数据分别是wifi的mac地址(BSSID),强度(level),名称(SSID),故实体类实现如下:
public class APData {
private String macAddr;
private int level;
private String name;
public APData(String macAddr, int level, String name) {
this.macAddr = macAddr;
this.level = level;
this.name = name;
}
public String getMacAddr() {
return macAddr;
}
public void setMacAddr(String macAddr) {
this.macAddr = macAddr;
}
public int getLevel() {
return level;
}
public void setLevel(int level) {
this.level = level;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
}
因为很久没有使用SQLite数据库了,所以在这里也记录一下...
public class MyDatabaseHelper extends SQLiteOpenHelper{
//建表语句
public static final String CREATE_TABLE = "create table apdata(" +
"id integer primary key autoincrement, " +
"ap_x integer, " +
"ap_y integer, " +
"ap_macaddr text, " +
"ap_level1 integer," +
"ap_level2 integer," +
"ap_level3 integer," +
"ap_name text)";
private Context mContext;
public MyDatabaseHelper(Context context, String name, SQLiteDatabase.CursorFactory factory, int version) {
super(context, name, factory, version);
mContext = context;
}
@Override
public void onCreate(SQLiteDatabase db) {
db.execSQL(CREATE_TABLE);
Toast.makeText(mContext, "Create table succeeded", Toast.LENGTH_SHORT).show();
}
@Override
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
}
}
github地址: https://github.com/zhangbz/APDataCollector