资源简介
根据室内多个wifi信号的强度进行定位;
可以扫描室内wifi的型号强度Value,并记录到数据库。
目前还未完善:需要手动修改代码将记录的数据写入定位代码。
但大体定位能够成功,概率90%准确定位率;
基本算法已经可以使用,只是一个可行的框架。
但仍旧需要再度开发。
代码片段和文件信息
/**
*
*/
package com.sample.testwifi;
import com.sample.testwifi.helper.DatabaseHelper;
import android.annotation.SuppressLint;
import android.app.ListActivity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
/**
* @author hubin2010
*
*/
@SuppressLint(“NewApi“)
public class DatabaseRecordAcivity extends ListActivity {
private Context mContext;
private static final String LOG_TAG = “WIFI_INFO“;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getActionBar().settitle(R.string.current_info);
setContentView(R.layout.wifi_list_db_info);
mContext = DatabaseRecordAcivity.this;
Intent intent = getIntent();
int location = intent.getIntExtra(“location“ 0);
Log.e(LOG_TAG “location: “ + location);
if (1 == location) {
((TextView) findViewById(R.id.tv_location))
.setVisibility(View.VISIBLE);
initContainLocation();
} else {
init();
}
}
private void init() {
SQLiteDatabase mDB = mContext.openOrCreateDatabase(
DatabaseHelper.DB_NAME MODE_PRIVATE null);
final Cursor cursor = mDB.query(DatabaseHelper.TB_NAME null null
null null null “location DESC“);
@SuppressWarnings(“deprecation“)
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this
R.layout.db_wifi_info_list cursor new String[] { “wifi_name“
“wifi_mac“ “wifi_level“ } new int[] {
R.id.db_wifi_name R.id.db_wifi_macAddress
R.id.db_wifi_level });
ListView lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView> parent View view
int position long id) {
cursor.moveToPosition(position);
Toast.makeText(DatabaseRecordAcivity.this
“This is No.[“ + position + “] Item“
Toast.LENGTH_SHORT).show();
}
});
}
private void initContainLocation() {
SQLiteDatabase mDB = mContext.openOrCreateDatabase(
DatabaseHelper.DB_NAME MODE_PRIVATE null);
final Cursor cursor = mDB.query(DatabaseHelper.TB_LOCATION_WIFI null
null null null null “location DESC“);
@SuppressWarnings(“deprecation“)
SimpleCursorAdapter adapter = new SimpleCursorAdapter(this
R.layout.db_wifi_info_location_list cursor new String[] {
“location“ “wifi_name“ “wifi_mac“ “wifi_level“ }
new int[] { R.id.db_wifi_location R.id.db_wifi_name
R.id.db_wifi_macAddress R.id.db_wifi_level });
ListView lv = (ListView) findViewById(android.R.id.list);
lv.setAdapter(adapter);
lv.setOnItemClickListener(new O
评论
共有 条评论